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;
#define pii pair<int, int>
int N, M;
vector<pii> computers;
vector<pii> orders;
void chm(int& i, int v){
i = max(i, v);
}
signed main(){
cin>>N;
for(int i = 0; i<N; i++){
int c, f, v;
cin>>c>>f>>v;
computers.push_back({f, v});
}
cin>>M;
for(int i = 0; i<M; i++){
int c, f, v;
cin>>c>>f>>v;
orders.push_back({f, v});
}
sort(computers.begin(), computers.end());
sort(orders.begin(), orders.end());
reverse(computers.begin(), computers.end());
reverse(orders.begin(), orders.end());
vector<vector<int>> dp(N+1, vector<int>(M+1, 0));
for(int cur_comp = 0; cur_comp<=N; cur_comp++){
for(int cur_order = 0; cur_order<=M; cur_order++){
int cur_v= dp[cur_comp][cur_order];
if(cur_comp<N){
chm(dp[cur_comp+1][cur_order], cur_v);
}
if(cur_order<M){
chm(dp[cur_comp][cur_order+1], cur_v);
}
if(cur_comp<N && cur_order<M){
if(computers[cur_comp].first>=orders[cur_order].first){
chm(dp[cur_comp+1][cur_order+1], cur_v + orders[cur_order].second - computers[cur_comp].second);
}
}
}
}
cout<<dp[N][M]<<endl;
}
# | 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... |