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 <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <utility>
#include <queue>
#include <map>
#include <iomanip>
#include <stack>
#include <fstream>
using namespace std;
long long int maximo(long long int s,vector<pair<long long int,long long int> >&p,long long int & hi,long long int & low,int nodo){
if(nodo==p.size()){
return s;
}
else{
if(hi==0 && low==1e15+1){
return max(maximo(s+p[nodo].second,p,p[nodo].first,p[nodo].first,nodo+1),maximo(s,p,hi,low,nodo+1));
}
if(p[nodo].first>=low && p[nodo].first<=hi){
return maximo(s+p[nodo].second,p,hi,low,nodo+1);
}
else if(p[nodo].first>hi){
return max(maximo(s+p[nodo].second-(p[nodo].first-hi),p,p[nodo].first,low,nodo+1),maximo(s,p,hi,low,nodo+1));
}
else{
return max(maximo(s+p[nodo].second-(low-p[nodo].first),p,hi,p[nodo].first,nodo+1),maximo(s,p,hi,low,nodo+1));
}
}
}
int main(){
int n;
cin>>n;
vector<pair<long long int,long long int> >p(n);
for(int i=0;i<n;i++){
cin>>p[i].first>>p[i].second;
}
long long int hi=0,low=1e15+1;
cout<<maximo(0,p,hi,low,0);
return 0;
}
Compilation message (stderr)
art.cpp: In function 'long long int maximo(long long int, std::vector<std::pair<long long int, long long int> >&, long long int&, long long int&, int)':
art.cpp:16:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
16 | if(nodo==p.size()){
| ~~~~^~~~~~~~~~
# | 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... |