제출 #715760

#제출 시각아이디문제언어결과실행 시간메모리
715760ovidiush11Art Exhibition (JOI18_art)C++14
0 / 100
0 ms212 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long int main() { ll n; cin>>n; vector<pair<ll,ll>> a(n); for(ll i = 0;i < n;i++)cin>>a[i].first>>a[i].second; sort(a.begin(),a.end()); a.push_back({1e15+1,0}); vector<pair<ll,ll>> v; for(ll i = 0;i < n;i++) { if(a[i].first == a[i+1].first)a[i+1].second += a[i].second; else v.push_back(a[i]); } n = v.size(); ll mx = v[0].second,x = mx,pos = 0; for(ll i = 1;i < n;i++) { x += v[i].second - (v[i].first - v[i-1].first); if(x >= mx) { mx = x; pos = i; } } ll ans = mx; for(ll i = 1;i < pos;i++) { mx -= v[i-1].second; mx += v[i].first - v[i-1].first; ans = max(ans,mx); } cout<<max(ans,v[pos].second); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...