P4266 [USACO18FEB] Rest Stops S

 

因为 FJ恒速 所以DT 相同 -》贪心-》c越大

min -》max 走到max

max-》min 刚追上就可以 走

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<bits/stdc++.h>
#define ll long long
#define ddd printf("--------------debug\n");
using namespace std;

ll l,n,rf,rb;
ll ans=0;
struct node{
    ll x,c;
}a[100010];
bool cmp(node x,node y){
    return x.c>y.c;
}
int main()
{
    ios::sync_with_stdio(false); cin.tie(0);
    cin>>l>>n>>rf>>rb;
    for(int i=1;i<=n;i++) cin>>a[i].x>>a[i].c;
    sort(a+1,a+1+n,cmp);
    
    ans=a[1].c*a[1].x*(rf-rb);int last=1;
    for(int i=2;i<=n;i++){
        if(a[i].x>a[last].x){
            ans+=(a[i].x-a[last].x)*(rf-rb)*a[i].c;
            last=i;
        }
    }
    cout<<ans<<'\n';
    
    return 0;
}
View Code

 

 
 
 
posted @ 2023-07-25 11:23  JMXZ  阅读(12)  评论(0)    收藏  举报