#include<iostream> #include<string> #include<cmath> #include<iomanip> #include<vector> #include<cstring> #include<algorithm> using namespace std; typedef struct book { int time; long long v; double tv; }book; bool cmp(book a, book b) { return a.tv > b.tv; } int main() { int n, m; cin >> n >> m; book a[301]; for (int i = 0;i < n;i++) { cin >> a[i].time >> a[i].v; a[i].tv = a[i].v / (double)a[i].time; } sort(a, a + n, cmp); long long int sum = 0; for (int i = 0;i < n;i++) { if (m - a[i].time >= 0) { m -= a[i].time; sum += a[i].v; } } cout << sum; } |
Double click to view unformatted code.