Submission #1268676

#TimeUsernameProblemLanguageResultExecution timeMemory
1268676orzminhhcCloud Computing (CEOI18_clo)C++20
100 / 100
334 ms2264 KiB
#include <bits/stdc++.h> using namespace std; #define all(x) begin(x), end(x) template<class T1, class T2> bool maximize(T1 &a, T2 b){ if(a < b) {a = b; return true;} return false; } template<class T1, class T2> bool minimize(T1 &a, T2 b){ if(a > b) {a = b; return true;} return false; } struct ITEM{ int c; long long f,v; int type; }; bool cmp(const ITEM &a, const ITEM &b){ if(a.f != b.f) return a.f > b.f; return a.type < b.type; } const long long inf = 1e18; const int maxc = 2e5+5; vector<long long> dp(maxc, -inf); void solve(){ int n; cin >> n; vector<ITEM> item; for(int i = 0; i < n; i ++){ int c; long long f, v; cin >> c >> f >> v; item.push_back({c,f,v,0}); } int m; cin >> m; for(int i = 0; i < m; i ++){ int c; long long f,v; cin >> c >> f >> v; item.push_back({c,f,v,1}); } sort(all(item), cmp); dp[0] = 0; int cur_c = 0; for(auto cur_item : item){ int c = cur_item.c, v = cur_item.v; cur_c += c; if(cur_item.type == 0){ for(int i = cur_c; i >= c; i --) if(dp[i-c] != -inf) maximize(dp[i], dp[i-c] - v); } else{ for(int i = 0; i <= cur_c - c; i++) if(dp[i+c] != -inf) maximize(dp[i], dp[i+c] + v); } } long long res = 0; for(int i = 0; i < maxc; i ++) maximize(res, dp[i]); cout << res; } signed main(){ ios::sync_with_stdio(0); cin.tie(0); if(fopen("A.inp", "r")){ freopen("A.inp","r", stdin); freopen("A.out","w", stdout); } solve(); return 0; }

Compilation message (stderr)

clo.cpp: In function 'int main()':
clo.cpp:70:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |         freopen("A.inp","r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~
clo.cpp:71:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   71 |         freopen("A.out","w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
#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...