# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1093295 | InvMOD | Cloud Computing (CEOI18_clo) | C++14 | 1 ms | 600 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;
template<typename T> bool ckmx(T& a, const T b){if(a < b) return a = b, true; return false;}
template<typename T> bool ckmn(T& a, const T b){if(a > b) return a = b, true; return false;}
const int N = 2e3+5;
int n, m, f[N];
int F[N], c[N], C[N];
ll v[N], V[N];
namespace Sub4{
bool ckSub()
{
int cnt_num = 0;
for(int i = 1; i <= max(n,m); i++){
cnt_num += (f[i] == 1);
cnt_num += (F[i] == 1);
}
return cnt_num == n+m;
}
const ll INF = 1e18;
vector<ll> f, g;
void solve()
{
int sumRoom = 0;
for(int i = 1; i <= n; i++){
sumRoom += c[i];
}
f.assign(sumRoom+1, INF);
sumRoom = 0;
for(int i = 1; i <= m; i++){
sumRoom += C[i];
}
g.assign(sumRoom+1, -INF);
f[0] = g[0] = 0;
for(int i = 1; i <= n; i++){
for(int j = (int)f.size()-1; j >= c[i]; j--){
ckmn(f[j], f[j - c[i]] + v[i]);
}
}
for(int i = 1; i <= m; i++){
for(int j = (int)g.size()-1; j >= C[i]; j--){
ckmx(g[j], g[j - C[i]] + V[i]);
}
}
//for(int j = (int)f.size()-2; j >= 0; j--) f[j] = min(f[j], f[j+1]);
ll answer = 0;
for(int i = 1; i <= min((int)f.size(), (int)g.size())-1; i++){
answer = max(answer, g[i] - f[i]);
}
cout << answer <<"\n";
}
}
void process()
{
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];
}
if(Sub4::ckSub()){
Sub4::solve();
}
}
int32_t main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
#define name "InvMOD"
if(fopen(name".INP", "r")){
freopen(name".INP", "r", stdin);
freopen(name".OUT", "w", stdout);
}
process();
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... |