# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1094957 | LTTrungCHL | Cloud Computing (CEOI18_clo) | C++17 | 572 ms | 2052 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.
///***LTT***///
/// ->NHAT QUOC GIA<- ///
#include<bits/stdc++.h>
//#pragma GCC optimize ("O3")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("popcnt")
//#define int long long
#define endl "\n"
#define F first
#define S second
#define pb push_back
using namespace std;
//vector <int> lg2;
//void MAKE_LOG_ARR(int n){
// lg2.resize(n + 3);
// for (int i = 1;i <= n;++i){
// lg2[i] = __lg(i);
// }
//}
const long long oo = 1e9+7;
const int N = 2 * 1e5 + 10;
int n, m;
struct com{
int c, f, v;
};
com a[5000];
long long dp[100005];
long long tmp[100005];
bool cmp(com x, com y){
if (x.f != y.f){
return x.f > y.f;
}
return x.v < y.v;
}
void solve(){
cin >> n;
int mx = 0;
for (int i = 1;i <= n;++i){
cin >> a[i].c >> a[i].f >> a[i].v;
a[i].v *= -1;
mx += a[i].c;
}
cin >> m;
for (int i = 1;i <= m;++i){
cin >> a[i + n].c >> a[i + n].f >> a[i + n].v;
a[i + n].c *= -1;
}
sort(a + 1,a + n + m + 1,cmp);
for (int j = 1;j <= mx;++j){
dp[j] = -oo * oo;
}
for (int i = 1;i <= n + m;++i){
for (int j = 0;j <= mx;++j){
tmp[j] = dp[j];
}
for (int j = 0;j <= mx;++j){
if (j + a[i].c >= 0 and j + a[i].c <= mx and dp[j] != -oo * oo){
tmp[j + a[i].c] = max(tmp[j + a[i].c], dp[j] + a[i].v);
}
}
for (int j = 0;j <= mx;++j){
dp[j] = tmp[j];
}
}
long long ans = 0;
for (int i = 0;i <= mx;++i){
ans = max(ans, dp[i]);
}
cout << ans;
return;
}
int main(){
ios_base::sync_with_stdio(NULL);
cin.tie(NULL);
cout.tie(NULL);
if (fopen("ltt.inp", "r")){
freopen("ltt.inp", "r", stdin);
freopen("ltt.out", "w", stdout);
}
// int t;
// 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... |