1 solutions
-
1
#include<bits/stdc++.h> using namespace std; struct jin { double zl,jz,xjb; }a[100000]; bool cmp (jin x,jin y) { if (x.xjb>y.xjb) { return 1; } else { return 0; } } int main () { int k; cin >> k; for (int i = 1; i <= k; i++) { int w,n; double sum=0; cin >> w >> n; for (int j = 1; j <= n; j++) { cin >> a[j].zl >> a[j].jz; a[j].xjb=a[j].jz/a[j].zl; } sort(a+1,a+1+n,cmp); int l=1; while (w&&l<=n) { if (a[l].zl<=w) { w -= a[l].zl; sum += a[l].jz; } else { sum += w*a[l].xjb; w=0; break; } l++; } printf("%.2f\n",sum); } return 0; }
- 1
Information
- ID
- 710
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 6
- Tags
- # Submissions
- 15
- Accepted
- 11
- Uploaded By