Submission #497619

#TimeUsernameProblemLanguageResultExecution timeMemory
497619penguin133Art Exhibition (JOI18_art)C++14
100 / 100
189 ms20940 KiB
#include <bits/stdc++.h> using namespace std; #define int long long struct Line { mutable int k, m, p; bool operator<(const Line& o) const { return k < o.k; } bool operator<(int x) const { return p < x; } }; struct LineContainer : multiset<Line, less<>> { // for doubles, use inf = 1/.0, div(a,b) = a / b static const int inf = 5e18;// implement this long double div(int a, int b) { // floored division return (long double)((long double)(a)/ (long double)(b)) ; } bool isect(iterator x, iterator y) { if (y == end()) return x->p = inf, 0; if (x->k == y->k) x->p = x->m > y->m ? inf : -inf; else x->p = div(y->m - x->m, x->k - y->k); return x->p >= y->p; } void add(int k, int m) { // insert y = kx + m auto z = insert({k, m, 0}), y = z++, x = y; while (isect(y, z)) z = erase(z); if (x != begin() && isect(--x, y)) isect(x, y = erase(y)); while ((y = x) != begin() && (--x)->p >= y->p) isect(x, erase(y)); } int query(int x) { // max query assert(!empty()); auto l = *lower_bound(x); return l.k * x + l.m; } }; // to use: // LineContainer hull; // hull.add(m, c); // hull.query(x); // to convert max queries to min queries: // hull.add(-m, -c); // -hull.query(x); int dp[1000005], P[1000005]; priority_queue<int>pq; pair<int, int> A[1000005]; main(){ ios::sync_with_stdio(0);cin.tie(0); int n;cin >> n; int cnt =0, ans = -1e17; for(int i=1;i<=n;i++){ cin >> A[i].first >> A[i].second; ans = max(ans, A[i].second); } sort(A+1, A+n+1); A[n+1].first = A[n].first; for(int i=1;i<=n;i++){ cnt += A[i].second; cnt = cnt - A[i+1].first + A[i].first; ans= max(ans, cnt + A[i+1].second); if(cnt < 0)cnt = 0; } cout << ans; }

Compilation message (stderr)

art.cpp:46:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   46 | main(){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...