deushiro

Untitled

Feb 5th, 2020
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4. #include <set>
  5. #include <cmath>
  6. #include <map>
  7. #include <string>
  8. #include <fstream>
  9.  
  10.  
  11. using namespace std;
  12.  
  13. ifstream in("input.txt");
  14. ofstream out("output.txt");
  15.  
  16. typedef long long ll;
  17.  
  18. int main()
  19. {
  20.     int t, n;
  21.     in >> t >> n;
  22.     vector<int> a(t + 1, -1);
  23.     a[0] = 0;
  24.     for (int i = 0; i < n; ++i) {
  25.         int ti, p;
  26.         in >> ti >> p;
  27.         for (int j = t; j > -1; --j) {
  28.             if (a[j] > -1 && j + ti <= t) {
  29.                 a[j + ti] = max(a[j + ti], a[j] + p);
  30.             }
  31.         }
  32.     }
  33.     int maxi = 0;
  34.     for (int i = 0; i <= t; ++i) {
  35.         maxi = max(a[i], maxi);
  36.     }
  37.     out << maxi << endl;
  38.     return 0;
  39.  
  40.  
  41.  
  42. }
Advertisement
Add Comment
Please, Sign In to add comment