Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorith>
- using namespace std;
- //ifstream cin(".in");
- //ofstream cout(".out");
- struct obc
- {
- float G, V;
- } v[1005];
- bool cond(obc i, obc j)
- {
- if(i.V / i.G > j.V / j.G) return true;
- else return false;
- }
- int main()
- {
- int n, GM;
- cin >> n >> GM;
- for(int i = 1; i <= n; ++i)
- {
- cin >> v[i].G >> v[i].V;
- }
- sort(v + 1, v + n + 1, cond);
- double S = 0, GR = 0;
- for(int i = 1; i <= n and GR <= GM; ++i)
- {
- if(GR + v[i].G <= GM)
- {
- GR += v[i].G;
- S += v[i].V;
- }
- else
- {
- double r = GM - GR, j = v[i].V / v[i].G;
- S += r * j;
- break;
- }
- }
- cout << S;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement