Submission #1093676

#TimeUsernameProblemLanguageResultExecution timeMemory
1093676luvnaCloud Computing (CEOI18_clo)C++14
18 / 100
172 ms1840 KiB
#include<bits/stdc++.h> #define endl "\n" using namespace std; typedef long long ll; template<class T> bool maximize(T& a, T b) {if(a < b) return a = b, true; return false;} const int N = 2005; const ll INF = 1e18; struct computer{ int cores, rate, price; bool operator < (const computer& a) const{ return (rate != a.rate) ? (rate > a.rate) : (cores > a.cores); } }; int n, m; computer a[N]; vector<ll> dp; void solve(){ cin >> n; int max_cores = 0; for(int i = 1; i <= n; i++){ int cores, rate, price; cin >> cores >> rate >> price; a[i] = {cores, rate, -price}; max_cores += cores; } cin >> m; for(int i = 1; i <= m; i++){ int cores, rate, price; cin >> cores >> rate >> price; a[i+n] = {-cores, rate, price}; } n += m; sort(a + 1, a + 1 + n); dp.resize(max_cores + 5, -INF); dp[0] = 0; for(int i = 1; i <= n; i++){ int cores = a[i].cores, p = a[i].price; vector<ll> f = dp; if(cores > 0){ //computer //knapsack : f[i] = dp[i-cores] + p for(int j = cores; j <= max_cores; j++){ f[j] = max(f[j], dp[j-cores] + 1LL*p); } } else{ //task //knapsack : f[i] = dp[i + cores] + p cores = -cores; for(int j = max_cores - cores; j >= 0; j--){ f[j] = max(f[j], dp[j + cores] + 1LL*p); } } swap(dp, f); } ll ans = 0; for(int i = 0; i <= max_cores; i++) maximize(ans, dp[i]); cout << ans; } signed main(){ ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0); #define task "task" if(fopen(task".INP", "r")){ freopen(task".INP", "r", stdin); freopen(task".OUT", "w", stdout); } int t; t = 1; //cin >> t; while(t--) solve(); }

Compilation message (stderr)

clo.cpp: In function 'int main()':
clo.cpp:87:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   87 |         freopen(task".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
clo.cpp:88:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   88 |         freopen(task".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...