제출 #670678

#제출 시각아이디문제언어결과실행 시간메모리
670678birthdaycakeArt Exhibition (JOI18_art)C++17
0 / 100
0 ms212 KiB
#ifndef _GLIBCXX_NO_ASSERT #include <cassert> #endif #include <cctype> #include <cerrno> #include <cfloat> #include <ciso646> #include <climits> #include <clocale> #include <cmath> #include <csetjmp> #include <csignal> #include <cstdarg> #include <cstddef> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #if __cplusplus >= 201103L #include <ccomplex> #include <cfenv> #include <cinttypes> #include <cstdbool> #include <cstdint> #include <ctgmath> #include <cwchar> #include <cwctype> #endif #include <algorithm> #include <bitset> #include <complex> #include <deque> #include <exception> #include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <new> #include <numeric> #include <ostream> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <streambuf> #include <string> #include <typeinfo> #include <utility> #include <valarray> #include <vector> #include <array> #include <atomic> #include <chrono> #include <condition_variable> #include <forward_list> #include <future> #include <initializer_list> #include <mutex> #include <random> #include <ratio> #include <regex> #include <scoped_allocator> #include <system_error> #include <thread> #include <tuple> #include <typeindex> #include <type_traits> #include <unordered_map> #include <unordered_set> #define int long long using namespace std; pair<int,int> a[500001],b[500001]; int seg[1<<19][2]; int N,Left,Right,W; void Update(int Pos, int V){ int ind = Pos + N - 1; seg[ind][W] = V; while(ind /= 2) seg[ind][W] = max(seg[ind * 2][W], seg[ind * 2 + 1][W]); } int Query(int l = 1, int r = N, int ind = 1){ if(l > Right or r < Left) return -1e18; if(l >= Left && r <= Right) return seg[ind][W]; int mid = (l + r) / 2; return max(Query(l, mid, ind * 2), Query(mid + 1, r, ind * 2 + 1)); } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, ans = 0; cin >> n; N = exp2(ceil(log2(n))); for(int i = 0; i < n; i++){ cin >> a[i].first >> a[i].second; } sort(a,a+n); for(int i = 0; i < n; i++){ if(i) a[i].second += a[i - 1].second; b[i].first = a[i].second - a[i].first; b[i].second = (i == 0 ? 0 : -a[i - 1].second) + a[i].first; W = 0; Update(i + 1, b[i].first); W = 1; Update(i + 1, b[i].second); } for(int i = 0; i < n; i++){ Left = 1; Right = i; W = 1; ans = max(ans, b[i].first + Query()); Left = i + 2; Right = n; W = 0; ans = max(ans, b[i].second + Query()); } cout << ans; 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...