分析
将物品积分升序排序,贪心计算即可
#include <iostream> #include <cstdio> #include <algorithm> using namespace std; typedef long long ll; struct Item { ll k,c; friend bool operator < (Item a,Item b) { return a.c<b.c; } }a[110]; int n,T; ll t[110],ans,sk; int main() { scanf("%d",&n); for (int i=1;i<=n;i++) scanf("%lld%lld",&a[i].k,&a[i].c); sort(a+1,a+n+1); scanf("%d",&T); for (int i=1;i<=T;i++) scanf("%lld",&t[i]); int i=1,j=1;ll k=1; while (i<=n) { if (j<=T) { if (t[j]>sk+a[i].k) sk+=a[i].k,ans+=k*a[i].k*a[i].c,i++; else { ll last=sk; while (j<=T&&t[j]<=sk+a[i].k) { ans+=k*(t[j]-last)*a[i].c; last=t[j]; j++;k++; } sk+=a[i].k;ans+=k*(sk-last)*a[i].c;i++; } } else { ans+=k*a[i].k*a[i].c; i++; } } printf("%lld",ans); }