제출 #713269

#제출 시각아이디문제언어결과실행 시간메모리
713269Spade1Art Exhibition (JOI18_art)C++14
100 / 100
226 ms28656 KiB
#include<bits/stdc++.h> //#include <grader.h> #define pii pair<int, int> #define pll pair<long long, long long> #define ll long long #define ld long double #define st first #define nd second #define pb push_back #define INF INT_MAX using namespace std; const int N = 5e5 + 10; pll a[N]; ll b[N], c[N], qs[N], qss[N]; void solve() { int n; cin >> n; for (int i = 1; i <= n; ++i) cin >> a[i].st >> a[i].nd; sort(a+1, a+n+1); for (int i = 1; i <= n; ++i) b[i] = -(a[i].st - a[i-1].st) + a[i].nd; for (int i = 1; i <= n; ++i) b[i] += b[i-1]; c[n] = b[n]; for (int i = n-1; i >= 1; --i) c[i] = max(c[i+1], b[i]); ll ans = 0; for (int i = 1; i <= n; ++i) { ans = max(ans, a[i].st-a[i-1].st + c[i] - b[i-1]); } cout << ans << '\n'; } int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); int t = 1; // cin >> t; while (t--) { solve(); } 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...