Submission #840565

# Submission time Handle Problem Language Result Execution time Memory
840565 2023-08-31T13:50:55 Z overwatch9 Art Exhibition (JOI18_art) C++17
100 / 100
807 ms 48244 KB
// slightly modified kadane's algorithm
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
vector <pair <ll, ll>> pnts;
int main() {
    int n;
    cin >> n;
    map <ll, ll> mp;
    for (int i = 0; i < n; i++) {
        ll a, b;
        cin >> a >> b;
        mp[a] += b;
    }
    ll ans = 0;
    ll mn = mp.begin()->first;
    ll mx = mn;
    vector <ll> dp(mp.size());
    int i = 0;
    ll tot_val = 0;
    for (auto it = mp.begin(); it != mp.end(); it++) {
        mx = it->first;
        tot_val += it->second;
        ll tp_ans = tot_val - (mx - mn);
        if (tp_ans <= it->second) {
            mn = mx = it->first;
            tp_ans = tot_val = it->second;
        }
        dp[i++] = tp_ans;
    }
    cout << *max_element(dp.begin(), dp.end()) << '\n';
}

Compilation message

art.cpp: In function 'int main()':
art.cpp:18:8: warning: unused variable 'ans' [-Wunused-variable]
   18 |     ll ans = 0;
      |        ^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 5 ms 596 KB Output is correct
28 Correct 4 ms 596 KB Output is correct
29 Correct 4 ms 596 KB Output is correct
30 Correct 5 ms 560 KB Output is correct
31 Correct 5 ms 596 KB Output is correct
32 Correct 4 ms 596 KB Output is correct
33 Correct 4 ms 596 KB Output is correct
34 Correct 5 ms 596 KB Output is correct
35 Correct 5 ms 596 KB Output is correct
36 Correct 4 ms 596 KB Output is correct
37 Correct 5 ms 596 KB Output is correct
38 Correct 4 ms 596 KB Output is correct
39 Correct 4 ms 596 KB Output is correct
40 Correct 4 ms 616 KB Output is correct
41 Correct 4 ms 560 KB Output is correct
42 Correct 5 ms 596 KB Output is correct
43 Correct 4 ms 596 KB Output is correct
44 Correct 5 ms 596 KB Output is correct
45 Correct 4 ms 596 KB Output is correct
46 Correct 5 ms 596 KB Output is correct
47 Correct 5 ms 724 KB Output is correct
48 Correct 4 ms 544 KB Output is correct
49 Correct 5 ms 596 KB Output is correct
50 Correct 5 ms 596 KB Output is correct
51 Correct 5 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 5 ms 596 KB Output is correct
28 Correct 4 ms 596 KB Output is correct
29 Correct 4 ms 596 KB Output is correct
30 Correct 5 ms 560 KB Output is correct
31 Correct 5 ms 596 KB Output is correct
32 Correct 4 ms 596 KB Output is correct
33 Correct 4 ms 596 KB Output is correct
34 Correct 5 ms 596 KB Output is correct
35 Correct 5 ms 596 KB Output is correct
36 Correct 4 ms 596 KB Output is correct
37 Correct 5 ms 596 KB Output is correct
38 Correct 4 ms 596 KB Output is correct
39 Correct 4 ms 596 KB Output is correct
40 Correct 4 ms 616 KB Output is correct
41 Correct 4 ms 560 KB Output is correct
42 Correct 5 ms 596 KB Output is correct
43 Correct 4 ms 596 KB Output is correct
44 Correct 5 ms 596 KB Output is correct
45 Correct 4 ms 596 KB Output is correct
46 Correct 5 ms 596 KB Output is correct
47 Correct 5 ms 724 KB Output is correct
48 Correct 4 ms 544 KB Output is correct
49 Correct 5 ms 596 KB Output is correct
50 Correct 5 ms 596 KB Output is correct
51 Correct 5 ms 596 KB Output is correct
52 Correct 807 ms 35516 KB Output is correct
53 Correct 700 ms 48076 KB Output is correct
54 Correct 716 ms 48172 KB Output is correct
55 Correct 726 ms 48080 KB Output is correct
56 Correct 750 ms 48064 KB Output is correct
57 Correct 727 ms 48152 KB Output is correct
58 Correct 716 ms 48244 KB Output is correct
59 Correct 720 ms 48120 KB Output is correct
60 Correct 700 ms 48144 KB Output is correct
61 Correct 727 ms 48052 KB Output is correct
62 Correct 758 ms 48228 KB Output is correct
63 Correct 701 ms 48152 KB Output is correct
64 Correct 735 ms 48084 KB Output is correct
65 Correct 706 ms 48192 KB Output is correct
66 Correct 711 ms 48152 KB Output is correct
67 Correct 745 ms 48128 KB Output is correct
68 Correct 726 ms 48160 KB Output is correct