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 ll long long int
#define ld long double
#define ii long long int
#define pb push_back
#define fi first
#define se second
#define Op operator
#define bp __builtin_popcount
#define Faster ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl '\n'
#define TT ll tt;cin>>tt;while(tt--){Test_Case();}
#define T Test_Case() ;
using namespace std;
const ii N = 5e5 , M = 1e6 , mod = 1e9 + 7 , Ones = 1 , Zero = 0;
const ll oo = 1e18 ;
pair<ll,ll> a[N + 5] ;
ii dp[N + 5] ;
bool comp(pair<ii,ii> aa , pair<ii,ii> bb) {
return (aa.fi < bb.fi || (aa.fi == bb.fi && aa.se > bb.se)) ;
}
void Test_Case(){
ii n , ans = 0 ; cin >> n ;
for(ii i = 1 ; i <= n ; i ++) {
cin >> a[i].fi >> a[i].se ;
}
sort(a + 1 , a + n + 1 , comp) ;
dp[1]= a[1].se ; ans = dp[1] ;
for(ii i = 2 ; i <= n ; i ++) {
dp[i] = a[i].se ;
dp[i] = max(dp[i] , dp[i - 1] + a[i].se - (a[i].fi - a[i - 1].fi)) ; ans = max(ans , dp[i]) ;
}
cout << ans << endl ;
}
int main(){
Faster
T ;
}
////// // // // // //////
// // // // // //
////// ////// //// //
// // // // //
////// // // // ////////
| # | 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... |