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>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define MOEZ ios_base::sync_with_stdio(false);cin.tie(NULL),cout.tie(NULL);
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define F first
#define S second
#define pb push_back
#define all(v) v.begin() , v.end()
#define eb emplace_back
#define getunique(v) {sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end());}
#define mem(d , x) memset(d , x , sizeof(d));
#define sz(x) (int)x.size()
//const int N = 2e5+5;
//const int M = 1e9+7;
//const ll inf = 1e17;
//const ld eps = 1e-6;
#define int long long
int n , s = 0;
//multiset<pair<int , int>>m;
signed main(){
MOEZ
cin >> n;
map<int , int>mp;
for(int i = 0; i < n;i++){
int a , b;
cin >> a >> b;
mp[a] += b;
}
vector<pair<int , int>>v;
int i = 0;
for(auto x:mp){
v.pb(x);
if(i){
v[i].S += v[i-1].S;
}
i++;
}
int ans = v[0].S, l = 0;
for(i = 0; i < n;i++){
int x = 0;
if(i)x = v[i-1].S;
for(int j = i; j < n;j++){
ans = max(ans , (v[j].S-x)-(v[j].F-v[i].F));
}
}
cout << ans;
}
Compilation message (stderr)
art.cpp: In function 'int main()':
art.cpp:44:23: warning: unused variable 'l' [-Wunused-variable]
44 | int ans = v[0].S, l = 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... |