| Run ID | 作者 | 问题 | 语言 | 测评结果 | 时间 | 内存 | 代码长度 | 提交时间 |
|---|---|---|---|---|---|---|---|---|
| 91945 | sh25_shenpy | 1-3-1 Mixing Milk 混合牛奶 | C++ | 无测评数据 | 0 MS | 0 KB | 717 | 2026-06-19 16:43:32 |
#include<bits/stdc++.h> using namespace std; struct nn { int p,a; }; bool cmp(nn x,nn y) { return x.p<y.p; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n,m; cin>>n>>m; nn x[m+1]; for(int i=1;i<=m;i++) { cin>>x[i].p>>x[i].a; } sort(x+1,x+1+m,cmp);//按牛奶的单价进行排序 int s=0; for(int i=1;i<=m;i++) { if(n<=x[i].a)//判断该农民提供的牛奶数量是否足够 { s+=x[i].p*n; n=0; break; } else { s+=x[i].p*x[i].a; n-=x[i].a; } } cout<<s; return 0; }