# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1093128 | InvMOD | Cloud Computing (CEOI18_clo) | C++14 | 15 ms | 348 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>
using namespace std;
using ll = long long;
const int N = 2e3+1;
const ll INF = 1e18;
int n, m;
int c[N], C[N], F[N], f[N];
ll V[N],v[N];
namespace Sub4{
bool ckSub()
{
int cnt = 0;
for(int i = 1; i <= n; i++) cnt += (f[i] == 1);
for(int i = 1; i <= m; i++) cnt += (F[i] == 1);
return cnt == (n+m);
}
vector<ll> f, g;
void solve()
{
int sum_room = 0;
for(int i = 1; i <= n; i++){
sum_room = sum_room + c[i];
}
f.assign(sum_room+1, INF);
sum_room = 0;
for(int i = 1; i <= m; i++){
sum_room = sum_room + C[i];
}
g.assign(sum_room+1, -INF);
f[0] = 0;
for(int i = 1; i <= n; i++){
for(int j = (int)f.size()-1; j >= c[i]; j--){
f[j] = min(f[j], f[j-c[i]] + v[i]);
}
}
g[0] = 0;
for(int i = 1; i <= m; i++){
for(int j = (int)g.size()-1; j >= C[i]; j--){
g[j] = max(g[j], g[j-C[i]] + V[i]);
}
}
for(int i = (int)f.size()-2; i >= 0; i--){
f[i] = min(f[i], f[i+1]);
}
ll answer = 0;
for(int i = 1; i < g.size(); i++){
answer = max(answer, (g[i] - f[i]));
}
cout << answer <<"\n";
return;
}
}
void inp()
{
cin >> n;
for(int i = 1; i <= n; i++){
cin >> c[i] >> f[i] >> v[i];
}
cin >> m;
for(int i = 1; i <= m; i++){
cin >> C[i] >> F[i] >> V[i];
}
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
#define name "task"
if(fopen(name".INP", "r")){
freopen(name".INP", "r", stdin);
freopen(name".OUT", "w", stdout);
}
inp();
if(Sub4::ckSub()){
Sub4::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... |