이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 , x = 0;
s = ans;
for(int r = 1;r < n;r++){
s = (v[r].S-x)-(v[r].F-v[l].F);
ans = max(ans , s);
if(v[r].S-v[r-1].S >= s){
ans = max(ans , v[r].S-v[r-1].S);
l = r;
x = v[r-1].S;
}
}
cout << ans;
}
# | 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... |