# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
362195 | sumit_kk10 | Cloud Computing (CEOI18_clo) | C++14 | 1138 ms | 2284 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long int
using namespace std;
const int MOD = 1e9 + 7;
const int N = 2e5 + 5;
long long int dp[1000000 + 1], sum = 0;
vector<pair<long long int, pair<long long int, long long int> > > v;
void solve() {
int n;
cin >> n;
for(int i = 0; i < n; ++i){
long long int c, f, p;
cin >> c >> f >> p;
sum += c;
p *= -1;
v.push_back({f, {c, p}});
}
int m;
cin >> m;
for(int i = 0; i < m; ++i){
long long int c, f, p;
cin >> c >> f >> p;
sum += c;
c *= -1;
v.push_back({f, {c, p}});
}
sort(v.begin(), v.end());
for(int i = 0; i < v.size(); ++i){
int f = v[i].first, c = v[i].second.first, p = v[i].second.second;
if(p < 0){
// buying a computer;
for(int cores = 0; cores <= sum; ++cores)
if(cores + c >= 0 and cores + c <= sum)
// if i have this many cores already;
dp[cores] = max(dp[cores], dp[cores + c] + p);
}
else{
// taking an order;
for(int cores = sum; cores >= 0; --cores)
// if i have this many cores already;
if(cores + c >= 0 and cores + c <= sum)
// I can take this order then.
dp[cores] = max(dp[cores], dp[cores + c] + p);
}
}
cout << dp[0] << "\n";
}
int main() {
fast;
int t = 1;
// cin >> t;
while(t--)
solve();
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |