24分,WA和RE都有······

P1208 [USACO1.3] 混合牛奶 Mixing Milk

sort应该是sort(a+1,a+m+1,cmp)吧,顺便开long long
by HZHDCM @ 2024-03-17 10:01:11


数组没开够
by lxc129 @ 2024-03-20 15:34:21


``` #include<bits/stdc++.h> using namespace std; struct w{ long long p,a; }c[1000000]; bool cmp(w a,w b) { return a.p<b.p; } int main() { int n,m,sum=0,t=0; cin>>n>>m; for(int i=0;i<m;i++) { cin>>c[i].p>>c[i].a; } sort(c,c+m,cmp); int x=0; while(t<=n&&x<=n) { if(t+c[x].a>n) { sum=sum+c[x].p*(n-t); break; }else{ sum=sum+c[x].p*c[x].a; t=t+c[x].a; } x++; } cout<<sum; return 0; } ```
by wran @ 2024-03-26 20:11:07


|