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 int long long
int n,m;
vector<pair<pair<int,int>,int>> table;
map<pair<int,int>,int> memo;
bool comp(pair<pair<int,int>,int> a, pair<pair<int,int>,int> b){
if(a.first.second==b.first.second){
if(a.second==b.second) return a.second>b.second;
return a.first.first>b.first.first;
}
return a.first.second>b.first.second;
}
signed main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> n;
table.resize(n);
for (int i = 0; i < n; i++) { cin >> table[i].first.first >> table[i].first.second >> table[i].second; table[i].second=-table[i].second;}
cin >> m;
table.resize(n+m);
for (int i = 0; i < m; i++) { cin >> table[i+n].first.first >> table[i+n].first.second >> table[i+n].second; table[i+n].first.first=-table[i+n].first.first; }
n+=m;
sort(table.begin(),table.end(),comp);
vector<pair<int,int>> dp1(n);
dp1[0]={0,0};
dp1[1]={table[0].second,table[0].first.first};
for (int i = 1; i < n; i++)
{
int _n=dp1.size();
int price=table[i].second;
int core=table[i].first.first;
for (int j = 0; j < _n; j++)
{
if(dp1[j].second+core>=0){
dp1.push_back({dp1[j].first+price, dp1[j].second+core});
}
}
}
int mx=0;
for (int i = 0; i < dp1.size(); i++) mx=max(dp1[i].first, mx);
cout << mx << "\n";
return 0;
}
Compilation message (stderr)
clo.cpp: In function 'int main()':
clo.cpp:43:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | for (int i = 0; i < dp1.size(); i++) mx=max(dp1[i].first, mx);
| ~~^~~~~~~~~~~~
# | 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... |