답안 #497619

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
497619 2021-12-23T11:42:51 Z penguin133 Art Exhibition (JOI18_art) C++14
100 / 100
189 ms 20940 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;
	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

art.cpp:46:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   46 | main(){
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 316 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 0 ms 336 KB Output is correct
7 Correct 0 ms 208 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 316 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 0 ms 336 KB Output is correct
7 Correct 0 ms 208 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 352 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 0 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 316 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 0 ms 336 KB Output is correct
7 Correct 0 ms 208 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 352 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 0 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 2 ms 472 KB Output is correct
28 Correct 2 ms 472 KB Output is correct
29 Correct 3 ms 424 KB Output is correct
30 Correct 2 ms 464 KB Output is correct
31 Correct 2 ms 492 KB Output is correct
32 Correct 2 ms 452 KB Output is correct
33 Correct 3 ms 464 KB Output is correct
34 Correct 2 ms 456 KB Output is correct
35 Correct 2 ms 472 KB Output is correct
36 Correct 2 ms 476 KB Output is correct
37 Correct 2 ms 468 KB Output is correct
38 Correct 2 ms 464 KB Output is correct
39 Correct 2 ms 468 KB Output is correct
40 Correct 2 ms 468 KB Output is correct
41 Correct 3 ms 476 KB Output is correct
42 Correct 2 ms 468 KB Output is correct
43 Correct 2 ms 464 KB Output is correct
44 Correct 2 ms 472 KB Output is correct
45 Correct 2 ms 488 KB Output is correct
46 Correct 2 ms 452 KB Output is correct
47 Correct 2 ms 464 KB Output is correct
48 Correct 2 ms 476 KB Output is correct
49 Correct 2 ms 592 KB Output is correct
50 Correct 3 ms 464 KB Output is correct
51 Correct 2 ms 464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 316 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 0 ms 336 KB Output is correct
7 Correct 0 ms 208 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 352 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 0 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 2 ms 472 KB Output is correct
28 Correct 2 ms 472 KB Output is correct
29 Correct 3 ms 424 KB Output is correct
30 Correct 2 ms 464 KB Output is correct
31 Correct 2 ms 492 KB Output is correct
32 Correct 2 ms 452 KB Output is correct
33 Correct 3 ms 464 KB Output is correct
34 Correct 2 ms 456 KB Output is correct
35 Correct 2 ms 472 KB Output is correct
36 Correct 2 ms 476 KB Output is correct
37 Correct 2 ms 468 KB Output is correct
38 Correct 2 ms 464 KB Output is correct
39 Correct 2 ms 468 KB Output is correct
40 Correct 2 ms 468 KB Output is correct
41 Correct 3 ms 476 KB Output is correct
42 Correct 2 ms 468 KB Output is correct
43 Correct 2 ms 464 KB Output is correct
44 Correct 2 ms 472 KB Output is correct
45 Correct 2 ms 488 KB Output is correct
46 Correct 2 ms 452 KB Output is correct
47 Correct 2 ms 464 KB Output is correct
48 Correct 2 ms 476 KB Output is correct
49 Correct 2 ms 592 KB Output is correct
50 Correct 3 ms 464 KB Output is correct
51 Correct 2 ms 464 KB Output is correct
52 Correct 189 ms 20880 KB Output is correct
53 Correct 189 ms 20780 KB Output is correct
54 Correct 183 ms 20812 KB Output is correct
55 Correct 177 ms 20820 KB Output is correct
56 Correct 171 ms 20940 KB Output is correct
57 Correct 167 ms 20764 KB Output is correct
58 Correct 173 ms 20936 KB Output is correct
59 Correct 171 ms 20820 KB Output is correct
60 Correct 180 ms 20776 KB Output is correct
61 Correct 171 ms 20600 KB Output is correct
62 Correct 171 ms 20816 KB Output is correct
63 Correct 168 ms 20812 KB Output is correct
64 Correct 165 ms 20744 KB Output is correct
65 Correct 185 ms 20808 KB Output is correct
66 Correct 174 ms 20888 KB Output is correct
67 Correct 174 ms 20716 KB Output is correct
68 Correct 165 ms 20864 KB Output is correct