Submission #858965

#TimeUsernameProblemLanguageResultExecution timeMemory
858965NursikArt Exhibition (JOI18_art)C++14
100 / 100
149 ms37820 KiB
#include <stdio.h> #include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <map> #include <queue> #include <random> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> #include <random> #include <chrono> #include <queue> #include <functional> #include <iostream> #include <queue> //#include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define mp make_pair #define f first #define s second #define ld long double const ll maxn = 1e6 + 1, maxm = 1e7 + 1; const ll mod = 1e9 + 7, mod2 = 998244353, inf = 1e9, block = 550, hb = 31, base = 1000050017; const ld eps = 1e-9; ll n; ll a[maxn], b[maxn], pref[maxn]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n; for (int i = 1; i <= n; ++i){ cin >> a[i] >> b[i]; } vector<pair<ll, ll>> vec; for (int i = 1; i <= n; ++i){ vec.pb(mp(a[i], b[i])); } sort(vec.begin(), vec.end()); for (int i = 0; i < n; ++i){ pref[i] = (i - 1 >= 0 ? pref[i - 1] : 0) + vec[i].s; } ll mx = -inf * inf, ans = -inf * inf; for (int i = n - 1; i >= 0; --i){ //cout << vec[i].f << " " << vec[i].s << '\n'; mx = max(mx, pref[i] - vec[i].f); ans = max(ans, mx - (i - 1 >= 0 ? pref[i - 1] : 0) + vec[i].f); } 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...