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>
#define endl "\n"
#define finp for(int i=0; i<n; i++)
#define fknp for(int k=0; k<n; k++)
#define yeap cout<<"YES"<<endl
#define nope cout<<"NO"<<endl
#define inpintn int n; cin>>n
#define inpintarrn int arr[n]; for(int i=0; i<n; i++){cin>>arr[i];}
#define inpllarrn long long arr[n]; for(int i=0; i<n; i++){cin>>arr[i];}
#define ll long long
#define pb push_back
#define answer cout<<ans<<endl
#define INF (ll)(1e18)
using namespace std;
int main ()
{
ll n;
cin>>n;
vector<vector<ll>> sizval;
for(int i=0; i<n; i++){
ll a, b;
cin>>a;
cin>>b;
sizval.push_back({a,b});
}
sort(sizval.begin(), sizval.end());
ll arr[n+1];
arr[0] = 0;
for(int i=1; i<=n; i++){
arr[i] = arr[i-1]+sizval[i-1][1];
}
ll ans = sizval[0][1]-sizval[0][0];
ll ans1;
for(int i=0; i<n; i++){
for(int j=i+1; j<n; j++){
ll minn = sizval[i][0];
ll maxx = sizval[j][0];
ll s = arr[j+1] - arr[i];
ans1 = s+minn-maxx;
ans = max(ans, ans1);
}
}
ll anss = sizval[0][1]-sizval[0][0];
for(int i=0; i<n; i++){
ll aa = sizval[i][1]-sizval[i][0];
ll anss = max(anss, aa);
}
ans = max(ans, anss);
cout<<ans<<endl;
// for(int i=0; i<=n; i++){
// cout << arr[i] << " ";
// }
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... |