Alex_tz307

Rucsac

Sep 12th, 2020 (edited)
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.33 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int N, G, g, p, a[10005];
  6.  
  7. ifstream fin ("rucsac.in");
  8. ofstream fout ("rucsac.out");
  9.  
  10. int main() {
  11.     fin >> N >> G;
  12.     for(int i = 1; i <= N; ++i) {
  13.         fin >> g >> p;
  14.         for(int j = G; j >= g; --j)
  15.         a[j] = max(a[j], a[j - g] + p);
  16.     }
  17.     fout << a[G];
  18. }
  19.  
Add Comment
Please, Sign In to add comment