제출 #418047

#제출 시각아이디문제언어결과실행 시간메모리
418047oofsizelargeArt Exhibition (JOI18_art)C++14
100 / 100
594 ms24944 KiB
#include <iostream> #include <algorithm> #include <vector> #include <climits> using namespace std; struct Artwork { long long a; int b; bool operator < (const Artwork& other) const { return a < other.a; } }; int main() { int n; cin >> n; vector < Artwork > gallery(n + 1); for (int i = 1; i <= n; ++i) { cin >> gallery[i].a >> gallery[i].b; } sort(gallery.begin() + 1, gallery.end()); vector < long long > bPartialSums(n + 1); for (int i = 1; i <= n; ++i) { bPartialSums[i] = bPartialSums[i - 1] + gallery[i].b; } long long suffixMax = LLONG_MIN; long long ans = 0LL; for (int i = n; i > 0; --i) { suffixMax = max(suffixMax, bPartialSums[i] - gallery[i].a); ans = max(ans, suffixMax - bPartialSums[i - 1] + gallery[i].a); } cout << ans << '\n'; 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...