Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
145447 | 江婉儿 | 储钱罐 | C++ | 解答错误 | 0 | 1 MS | 264 KB | 638 | 2024-05-05 08:48:19 |
#include<bits/stdc++.h> using namespace std; struct qian { int p,w; double aa; }a[10005]; bool cmp(qian c,qian d) { return c.aa<d.aa; } int main() { int t,e,f,n; cin>>t; for(int i=1;i<=t;i++) { cin>>e>>f>>n; int v=f-e; for(int j=1;j<=n;j++) { cin>>a[j].p>>a[j].w; a[j].aa=a[j].p*1.0/a[j].w; } sort(a+1,a+1+n,cmp); int s1=0,s2=0,top=1; while(s2<v) { s1+=v/a[top].w*a[top].p; s2+=v/a[top].w*a[top].w; top++; if(top==n)break; } if(s2==v)printf("The minimum amount of money in the piggy-bank is %d.\n",s1); else cout<<"This is impossible."; } return 0; }