JZOJ 3012. 购买
题目
分析
tanxin water
代码
1 #include <iostream> 2 #include <cstdio> 3 #include <cstdlib> 4 #include <algorithm> 5 #include <cstring> 6 #include <string> 7 #include <cmath> 8 #define MAXN 105 9 using namespace std; 10 typedef long long ll; 11 int n,m,p=1,q=1,bl=1; 12 ll t[MAXN],ans,cnt,temp,sum; 13 struct Node 14 { 15 ll k,c; 16 }g[MAXN]; 17 inline bool cmp(Node x,Node y) 18 { 19 return x.c<y.c; 20 } 21 int main() 22 { 23 scanf("%d",&n); 24 for (int i=1;i<=n;i++) 25 scanf("%lld%lld",&g[i].k,&g[i].c),sum+=g[i].k; 26 scanf("%d",&m); 27 for (int i=1;i<=m;i++) 28 scanf("%lld",&t[i]); 29 for (int i=2;i<=m;i++) 30 for (int j=1;j<i;j++) 31 t[i]-=t[j]; 32 sort(g+1,g+1+n,cmp); 33 while(cnt<sum) 34 { 35 if(t[p]<g[q].k) 36 { 37 ans+=t[p]*g[q].c*bl; 38 g[q].k-=t[p]; 39 bl++; 40 cnt+=t[p]; 41 p++; 42 } 43 else 44 { 45 ans+=g[q].k*g[q].c*bl; 46 t[p]-=g[q].k; 47 cnt+=g[q].k; 48 q++; 49 } 50 if(p>m) 51 { 52 for (int i=q;i<=n;i++) 53 ans+=g[i].c*g[i].k*bl; 54 cnt=sum; 55 } 56 //cout<<q<<" "<<ans<<endl; 57 } 58 cout<<ans<<endl; 59 return 0; 60 }
为何要逼自己长大,去闯不该闯的荒唐