Submission #791833

#TimeUsernameProblemLanguageResultExecution timeMemory
791833BoomydayArt Exhibition (JOI18_art)C++14
0 / 100
1 ms212 KiB
#include <iostream> #include <vector> #include <algorithm> #include <climits> using namespace std; int main() { std::ios::sync_with_stdio(false); cin.tie(NULL); int bestScore = 0; int N; cin >> N; vector<pair<int, int>> arts; const long long INF = 1e18; for (int i = 0; i < N; i++) { int a, b; cin >> a >> b; arts.push_back(make_pair(a, b)); } sort(arts.begin(), arts.end(), [](const pair<int, int>& x, const pair<int, int>& y) { return x.first < y.first; }); vector<int> A, B; for (const auto& art : arts) { A.push_back(art.first); B.push_back(art.second); } vector<long long> prefs = {0}; for (int i = 0; i < N; i++) { prefs.push_back(prefs.back() + B[i]); } vector<long long> prefs_orig = prefs; for (int i = 0; i < N; i++) { prefs[i + 1] -= A[i]; } vector<long long> suffix_maxs(N + 1, -INF); suffix_maxs[N] = prefs[N]; for (int i = N - 1; i >= 0; i--) { suffix_maxs[i] = max(suffix_maxs[i + 1], prefs[i]); } long long mx = *max_element(B.begin(), B.end()); for (int st = 0; st < N; st++) { long long bestmx = suffix_maxs[st + 1]; mx = max(mx, bestmx - prefs_orig[st] + A[st]); } cout << mx << endl; return 0; }

Compilation message (stderr)

art.cpp: In function 'int main()':
art.cpp:9:9: warning: unused variable 'bestScore' [-Wunused-variable]
    9 |     int bestScore = 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...