POJ 2323 贪心

题意:
这里写图片描述
这里写图片描述
思路:



如果当前的c>之前的c+s 那么之前的合适 一直贪下去就好了

//By SiriusRen
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define int long long
int n,s,rec=1,c[10500],y[10500],ans;
signed main(){
    scanf("%lld%lld",&n,&s);
    for(int i=1;i<=n;i++)
        scanf("%lld%lld",&c[i],&y[i]);
    for(int i=1;i<=n;i++){
        if(c[i-1]+s<c[i])ans+=y[i]*(c[rec]+s*(i-rec));
        else rec=i,ans+=y[i]*c[i];
    }
    printf("%lld
",ans);
}

这里写图片描述

原文地址:https://www.cnblogs.com/SiriusRen/p/6532210.html