제출 #723132

#제출 시각아이디문제언어결과실행 시간메모리
723132adrilenArt Exhibition (JOI18_art)C++17
100 / 100
206 ms20688 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; typedef pair<ll, ll> pii; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; vector <pii> v(n); for (pii &p : v) cin >> p.first >> p.second; sort(v.begin(), v.end()); // Make prefix sum for (int i = 1; i < n; i++) v[i].second += v[i - 1].second; ll output = 0; int i, j = 0; for (i = 0; i < n; i++) { // When i changes, you could increase j to i if (v[i].second - (i != 0 ? v[i - 1].second : 0) > v[i].second - (j != 0 ? v[j - 1].second : 0) - v[i].first + v[j].first) j = i; output = max(output, v[i].second - (j != 0 ? v[j - 1].second : 0) - v[i].first + v[j].first); } cout << output << "\n"; } /* Will be continous segments. ....a....b.... then if c > b -> d >=a ....ddd...c */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...