1 solutions
-
0
C++ :
#include <bits/stdc++.h> #define N 100005 using namespace std; struct Item{ int m,v; double p; friend bool operator < (Item a,Item b){ return a.p > b.p; } }a[N]; int main(){ int n,t; cin >> n >> t; for (int i = 1;i<=n;i++){ int m,v; cin >> m >> v; a[i] = {m,v,1.0*v/m}; } sort(a+1,a+1+n); double ans = 0; for (int i = 1;i<=n;i++){ if (t > a[i].m) { ans += a[i].v; t -= a[i].m; } else{ ans += a[i].p * t; break; } } // cout << ans; printf("%.2lf",ans); return 0; }
- 1
Information
- ID
- 14
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- 10
- Tags
- # Submissions
- 1
- Accepted
- 1
- Uploaded By