Submission #807982

#TimeUsernameProblemLanguageResultExecution timeMemory
807982gun_ganCloud Computing (CEOI18_clo)C++17
72 / 100
449 ms1716 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int MX = 4005;
int N, M;
vector<array<int,3>> a;

ll dp[2][MX * 20];

int main() {
      cin.tie(0); ios_base::sync_with_stdio(0);

      for(int i = 0; i < MX * 20; i++) 
            dp[0][i] = dp[1][i] = -1e18;
      
      cin >> N;
      for(int i = 1; i <= N; i++) {
            int c, f, v;
            cin >> c >> f >> v;
            a.push_back({f, c, -v});
      }
      cin >> M;

      for(int i = 1; i <= M; i++) {
            int c, f, v;
            cin >> c >> f >> v;
            a.push_back({f, -c, v});
      }

      sort(a.rbegin(), a.rend());
      
      dp[0][0] = 0;
      for(int i = 0; i < N + M; i++) {
            auto [f, c, v] = a[i];
            int k = i & 1;
            for(int j = 0; j < MX * 20; j++) {
                  dp[k ^ 1][j] = dp[k][j];
                  if(j - c >= 0 && j - c < MX * 20)
                        dp[k ^ 1][j] = max(dp[k ^ 1][j], dp[k][j - c] + v);
            }
      }

      cout << *max_element(dp[(N + M) & 1], dp[(N + M) & 1] + 20 * MX) << '\n';
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...