Submission #588911

#TimeUsernameProblemLanguageResultExecution timeMemory
588911FedShatArt Exhibition (JOI18_art)C++17
50 / 100
1058 ms24640 KiB
#include <bits/stdc++.h> using namespace std; #define all(c) c.begin(), c.end() #define rall(c) c.rbegin(), c.rend() using ll = long long; constexpr int INF = (numeric_limits<int>::max()) / 2; constexpr ll INFLL = (numeric_limits<ll>::max()) / 2; template<class T> istream &operator>>(istream &is, vector<T> &a) { for (auto &i: a) { is >> i; } return is; } int main() { cin.tie(0)->sync_with_stdio(0); #ifdef __APPLE__ freopen("input.txt", "r", stdin); #endif int n; cin >> n; vector<pair<ll, ll>> v(n); for (int i = 0; i < n; ++i) { cin >> v[i].first >> v[i].second; } sort(all(v)); vector<ll> pref(n + 1); for (int i = 1; i <= n; ++i) { pref[i] = pref[i - 1] + v[i - 1].second; } ll ans = -INFLL, mn = INFLL; auto add = [&](int i) { if (i + 1 < n) { mn = min(mn, pref[i] - v[i + 1].first); } }; add(0); for (int i = 1; i <= n; ++i) { for (int j = 0; j < i; ++j) { ans = max(ans, pref[i] - pref[j] - (v[i - 1].first - v[j].first)); } // ans = max(ans, pref[i] - v[i - 1].first - mn); // add(i); } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...