# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
994481 | cpdreamer | Cloud Computing (CEOI18_clo) | C++14 | 28 ms | 1372 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;
pair<int,int>A[n+1];
int Per[n+1],P[n+1];
for(int i=1;i<=n;i++){
int b;
cin>>b>>A[i].F>>A[i].S;
}
sort(A+1,A+n+1);
for(int i=1;i<=n;i++){
Per[i]=A[i].F;
P[i]=A[i].S;
}
int m;cin>>m;
pair<int,int>B[m+1];
int Per1[m+1],P1[m+1];
for(int i=1;i<=m;i++){
int b;
cin>>b>>B[i].F>>B[i].S;
}
sort(B+1,B+1+m);
for(int i=1;i<=m;i++){
Per1[i]=B[i].F;
P1[i]=B[i].S;
}
ll dp[n+1][m+1];
memset(dp,0,sizeof(dp));
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
//dp[i][j]=buy form first i and sell to first j
for(int g=j;g>=1;g--){
ll c=dp[i-1][g-1];
if(Per[i]>=Per1[g])
c+=P1[g]-P[i];
dp[i][j]=max(dp[i][j],c);
dp[i][j]=max(dp[i][j],max(dp[i-1][j],dp[i][j-1]));
}
}
}
cout<<dp[n][m]<<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... |