This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*
* created by Mohamed hossam
#### #### ## ##
## ## ## ## ##### ## ## ###### ##
## ## ## ## ## ## ####### ############## ## ## ########
## ###### ## ## ## ####### ############## ######### ## ##
## ## ## ## ## ## ## ## ## ## ## ##
### ### ##### ## ## ## ## ## ####### ########
*/
#include <bits/stdc++.h>
#define ll long long
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
ll n;
pair<ll,ll>a[5001];
ll p=-1e5;
void solve(ll i,ll sum,ll max1,ll min1)
{
if(i==n&&max1!=-1e9&&min1!=1e9){p=max(p,sum-(max1-min1));return;}if(i>=n)return;
solve(i+1,sum,max1,min1);
solve(i+1,sum+a[i].second,max(max1,a[i].first),min(a[i].first,min1));
}
int main()
{
fast;
cin>>n;
for(ll i=0; i<n; i++)
{
cin>>a[i].first>>a[i].second;
}
solve(0,0,-1e9,1e9);
cout<<p;
return 0;
}
# | 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... |