Submission #550541

#TimeUsernameProblemLanguageResultExecution timeMemory
550541KiprasArt Exhibition (JOI18_art)C++17
100 / 100
641 ms52296 KiB
#include <bits/stdc++.h> typedef long long ll; using namespace std; const ll maxN = 5e5+10; vector<pair<ll, ll>> a; map<ll, ll> b; ll n; int main() { ios_base::sync_with_stdio(0);cin.tie(nullptr); cin>>n; ll mx = 0; for(int i = 0; i < n; i++){ ll aa, bb; cin>>aa>>bb; a.push_back({aa, bb}); mx=max(mx, bb); } for(int i = 0; i < n; i++){ b[a[i].first]+=a[i].second; } a.clear(); for(auto i : b){ a.push_back({i.first, i.second}); } sort(a.begin(), a.end()); n = a.size(); for(int i = 0; i < n; i++){ mx=max(mx, a[i].second); } ll cur = a[0].second; for(int i = 1; i < n; i++){ cur = max(cur+a[i].second-abs(a[i].first-a[i-1].first), a[i].second); mx=max(mx, cur); } cout<<mx; 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...