# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1091273 | nghiaaa | Cloud Computing (CEOI18_clo) | C++14 | 577 ms | 2140 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;
//variable
#define ld long double
#define ll long long
#define db double
#define ii pair<int,int>
#define f first
#define s second
#define mp make_pair
#define mt make_tuple
//vector
#define pb push_back
#define all(v) v.begin(),v.end()
#define len(a) (int)a.length()
#define sz(a) (int)a.size()
//mask
#define BIT(i) (1LL<<(i))
//better code, debugger
#define watch(n) cerr << #n << ": " << n << endl
#define debug(x) for (auto p: x) cerr<<p<<' ';cerr<<endl
#define forw(i,j,z) for(int i=(int)j;i<=(int)z;i++)
#define ford(i,j,z) for (int i=(int)j;i>=(int)z;i--)
#define fIlE "test."
//auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
//mt19937 RAND(seed);
const int mod = 998244353;
inline int add(int u,int v){u+=v;if(u>=mod)u-=mod;return u;}
inline int dec(int u,int v){u-=v;if(u<0)u+=mod;return u;}
inline int mul(int u,int v){return (ll)u*v%mod;}
const int N = 2000 + 1;
struct E{
int slot, tt, cost;
};
E a[2 * N];
bool cmp(E u, E v)
{
if (u.tt != v.tt)
return u.tt > v.tt;
return u.cost < v.cost;
}
int n, m;
void solve()
{
cin >> n;
int maxC = 0;
forw(i, 1, n){
cin >> a[i].slot >> a[i].tt >> a[i].cost;
a[i].cost *= -1;
maxC += a[i].slot;
}
cin >> m;
forw(i, n + 1, n + m){
cin >> a[i].slot >> a[i].tt >> a[i].cost;
a[i].slot *= -1;
}
sort(a + 1, a + n + m + 1, cmp);
vector<ll> dp(maxC + 1, LLONG_MIN);
dp[0] = 0;
forw(i, 1, n + m){
const E u = a[i];
vector<ll> re(dp);
forw(c, 0, maxC)
if (c + u.slot >= 0 && c + u.slot <= maxC && dp[c] != LLONG_MIN)
re[c + u.slot] = max(re[c + u.slot], dp[c] + u.cost);
dp = re;
}
cout << *max_element(all(dp));
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
if (fopen(fIlE"inp", "r"))
freopen(fIlE"inp","r",stdin), freopen(fIlE"out","w",stdout);
//time_t TIME_TU=clock();
int t=1;
// cin>>t;
while(t--)
solve();
//time_t TIME_TV=clock();
//cerr<<(db)(TIME_TV-TIME_TU)/CLOCKS_PER_SEC<<endl;
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... |