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
#define pii pair<int,pair<int,pair<int,int> > >
#define f first
#define s second
#define LLONG_MIN -10000000000000000
#define maxn 100050
int32_t main(){
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int no_of_input;
int input1,input2,input3,input4;
vector<pii> vect1;
cin >> no_of_input;
for(int i=0;i<no_of_input;i++){
cin >> input1 >> input2 >> input3;
vect1.push_back({input2,{1,{input1,input3}}});//frequency,sub,corecount,price
}
cin >> no_of_input;
for(int i=0;i<no_of_input;i++){
cin >> input1 >> input2 >> input3;
vect1.push_back({input2,{-1,{input1,input3}}});//frequency,sub,corecount,price
}
sort(vect1.begin(),vect1.end());
reverse(vect1.begin(),vect1.end());
vector<int> dp(maxn,LLONG_MIN);
dp[0] = 0;
vector<int> temp(maxn,LLONG_MIN);
for(auto k:vect1){
//cout << k.f << " " << k.s.f << " " << k.s.s.f << " " << k.s.s.s << "\n";
}
for(int i=0;i<vect1.size();i++){
temp = dp;
int q = vect1[i].s.s.f,price = vect1[i].s.s.s;
if(vect1[i].s.f==1){//add stuff
for(int j=0;j<=dp.size()-1-q;j++){
temp[j+q] = max(temp[j+q],dp[j]-price);
}
}
else{//subtract stuff
for(int j=dp.size()-1;j>=q;j--){
temp[j-q] = max(temp[j-q],dp[j]+price);
}
}
dp = temp;
}
int ans = 0;
for(auto k:dp){
ans = max(ans,k);
}
cout << ans;
}
Compilation message (stderr)
clo.cpp:7:0: warning: "LLONG_MIN" redefined
#define LLONG_MIN -10000000000000000
In file included from /usr/lib/gcc/x86_64-linux-gnu/7/include-fixed/limits.h:194:0,
from /usr/lib/gcc/x86_64-linux-gnu/7/include-fixed/syslimits.h:7,
from /usr/lib/gcc/x86_64-linux-gnu/7/include-fixed/limits.h:34,
from /usr/include/c++/7/climits:42,
from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:39,
from clo.cpp:1:
/usr/include/limits.h:131:0: note: this is the location of the previous definition
# define LLONG_MIN (-LLONG_MAX-1)
clo.cpp: In function 'int32_t main()':
clo.cpp:31:12: warning: variable 'k' set but not used [-Wunused-but-set-variable]
for(auto k:vect1){
^
clo.cpp:34:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<vect1.size();i++){
~^~~~~~~~~~~~~
clo.cpp:38:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=0;j<=dp.size()-1-q;j++){
~^~~~~~~~~~~~~~~
clo.cpp:13:28: warning: unused variable 'input4' [-Wunused-variable]
int input1,input2,input3,input4;
^~~~~~
# | 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... |