Submission #497612

# Submission time Handle Problem Language Result Execution time Memory
497612 2021-12-23T11:13:10 Z penguin133 Art Exhibition (JOI18_art) C++14
0 / 100
1 ms 204 KB
#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;
	for(int i=1;i<=n;i++){
		cin >> A[i].first >> A[i].second;
	}
	sort(A+1, A+n+1);
	int cnt = 0, ans = -1e17;
	int in = 1;
	for(int i=1;i<=n;i++){
		cnt += A[i].second;
		cnt = cnt - A[i].first + A[in].first;
		ans=  max(ans, cnt);
		if(cnt < 0)cnt = 0, in = i+1;
		else in = i
		;
	}
	cout << ans;
	
}

Compilation message

art.cpp:46:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   46 | main(){
      | ^~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -