# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
994432 | cpdreamer | Cloud Computing (CEOI18_clo) | C++14 | 250 ms | 2068 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>
#include <ext/pb_ds/assoc_container.hpp>
#include <utility>
using namespace __gnu_pbds;
using namespace std;
typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
const int max_n=INT_MAX;
typedef long long ll;
#define LLM LONG_LONG_MAX
#define pb push_back
#define F first
#define L length()
#define all(v) v.begin(),v.end()
#define V vector
#define S second
const long long MOD = 1000000007; // 1e9 + 7
void file(){
freopen("input.txt.txt","r",stdin);
freopen("output.txt.txt","w",stdout);
}
void setio(string s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
void solve(){
int n;
cin>>n;
int C[n],P[n];
for(int i=0;i<n;i++){
int b;
cin>>C[i]>>b>>P[i];
}
int m;cin>>m;
int C1[m],P1[m];
for(int i=0;i<m;i++){
int b;
cin>>C1[i]>>b>>P1[i];
}
ll Buy[(int)1e5+1];
ll Sell[(int)1e5+1];
memset(Buy,-1,sizeof(Buy));
memset(Sell,-1,sizeof(Sell));
Buy[0]=0;
Sell[0]=0;
for(int i=0;i<n;i++){
for(int j=1e5;j>=C[i];j--){
if(Buy[j-C[i]]!=-1){
if(Buy[j]!=-1){
Buy[j]=min(Buy[j],Buy[j-C[i]]+P[i]);
}
else
Buy[j]=Buy[j-C[i]]+P[i];
}
}
}
for(int i=0;i<m;i++){
for(int j=1e5;j>=C1[i];j--){
if(Sell[j-C1[i]]!=-1){
if(Sell[j]!=-1){
Sell[j]=max(Sell[j],Sell[j-C1[i]]+P1[i]);
}
else
Sell[j]=Sell[j-C1[i]]+P1[i];
}
}
}
int index;
for(int i=0;i<=1e5;i++){
if(Buy[i]!=-1)
index=i;
}
ll s=Buy[index];
for(int i=index;i>=0;i--){
if(Buy[i]!=-1){
Buy[i]=min(s,Buy[i]);
s=min(s,Buy[i]);
}
}
ll ans=0;
for(int i=0;i<=1e5;i++){
if(Buy[i]!=-1 && Sell[i]!=-1){
ans=max(ans,Sell[i]-Buy[i]);
}
}
cout<<ans<<endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
//file();
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... |