Submission #483989

# Submission time Handle Problem Language Result Execution time Memory
483989 2021-11-01T18:44:39 Z ak2006 Art Exhibition (JOI18_art) C++14
100 / 100
537 ms 71828 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vb = vector<bool>;
using vvb = vector<vb>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
const ll mod = 1e9 + 7,inf = 1e18;
#define pb push_back
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
void setIO()
{
    fast;
}
int main()
{
    setIO();
    int n;
    cin>>n;
    vvl a(n + 1,vl(2));
    for (int i = 1;i<=n;i++)cin>>a[i][0]>>a[i][1];
    sort(a.begin() + 1,a.end());
    vl pre(n + 1),dp(n + 1);
    ll ans = 0;
    for (int i = 1;i<=n;i++)pre[i] = pre[i - 1] + a[i][1];
    multiset<ll>s;
    for (int i = 1;i<=n;i++){
        dp[i] = pre[i] - a[i][0] + a[1][0];
        if (!s.empty()){
            dp[i] = max(dp[i],pre[i] - a[i][0] + *(--s.end()));
        }
        ans = max(ans,dp[i]);
        // for (int j = i - 1;j>=0;j--){
        //     dp[i] = max(dp[i],pre[i] - pre[j] - a[i][0] + a[j + 1][0]);
        //     ans = max(ans,dp[i]);
        // }
        if (i != n)s.insert(-pre[i] + a[i + 1][0]);
    }
    cout<<ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 0 ms 332 KB Output is correct
23 Correct 0 ms 332 KB Output is correct
24 Correct 1 ms 268 KB Output is correct
25 Correct 0 ms 332 KB Output is correct
26 Correct 0 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 0 ms 332 KB Output is correct
23 Correct 0 ms 332 KB Output is correct
24 Correct 1 ms 268 KB Output is correct
25 Correct 0 ms 332 KB Output is correct
26 Correct 0 ms 332 KB Output is correct
27 Correct 3 ms 844 KB Output is correct
28 Correct 4 ms 844 KB Output is correct
29 Correct 3 ms 844 KB Output is correct
30 Correct 5 ms 844 KB Output is correct
31 Correct 3 ms 844 KB Output is correct
32 Correct 3 ms 876 KB Output is correct
33 Correct 3 ms 844 KB Output is correct
34 Correct 3 ms 844 KB Output is correct
35 Correct 3 ms 844 KB Output is correct
36 Correct 3 ms 844 KB Output is correct
37 Correct 4 ms 844 KB Output is correct
38 Correct 3 ms 836 KB Output is correct
39 Correct 3 ms 844 KB Output is correct
40 Correct 3 ms 844 KB Output is correct
41 Correct 3 ms 844 KB Output is correct
42 Correct 3 ms 844 KB Output is correct
43 Correct 3 ms 844 KB Output is correct
44 Correct 3 ms 904 KB Output is correct
45 Correct 3 ms 844 KB Output is correct
46 Correct 3 ms 844 KB Output is correct
47 Correct 3 ms 844 KB Output is correct
48 Correct 3 ms 844 KB Output is correct
49 Correct 3 ms 844 KB Output is correct
50 Correct 3 ms 844 KB Output is correct
51 Correct 3 ms 844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 0 ms 332 KB Output is correct
23 Correct 0 ms 332 KB Output is correct
24 Correct 1 ms 268 KB Output is correct
25 Correct 0 ms 332 KB Output is correct
26 Correct 0 ms 332 KB Output is correct
27 Correct 3 ms 844 KB Output is correct
28 Correct 4 ms 844 KB Output is correct
29 Correct 3 ms 844 KB Output is correct
30 Correct 5 ms 844 KB Output is correct
31 Correct 3 ms 844 KB Output is correct
32 Correct 3 ms 876 KB Output is correct
33 Correct 3 ms 844 KB Output is correct
34 Correct 3 ms 844 KB Output is correct
35 Correct 3 ms 844 KB Output is correct
36 Correct 3 ms 844 KB Output is correct
37 Correct 4 ms 844 KB Output is correct
38 Correct 3 ms 836 KB Output is correct
39 Correct 3 ms 844 KB Output is correct
40 Correct 3 ms 844 KB Output is correct
41 Correct 3 ms 844 KB Output is correct
42 Correct 3 ms 844 KB Output is correct
43 Correct 3 ms 844 KB Output is correct
44 Correct 3 ms 904 KB Output is correct
45 Correct 3 ms 844 KB Output is correct
46 Correct 3 ms 844 KB Output is correct
47 Correct 3 ms 844 KB Output is correct
48 Correct 3 ms 844 KB Output is correct
49 Correct 3 ms 844 KB Output is correct
50 Correct 3 ms 844 KB Output is correct
51 Correct 3 ms 844 KB Output is correct
52 Correct 410 ms 58936 KB Output is correct
53 Correct 424 ms 71800 KB Output is correct
54 Correct 444 ms 71604 KB Output is correct
55 Correct 453 ms 71572 KB Output is correct
56 Correct 478 ms 71596 KB Output is correct
57 Correct 441 ms 71620 KB Output is correct
58 Correct 491 ms 71828 KB Output is correct
59 Correct 431 ms 71620 KB Output is correct
60 Correct 430 ms 71620 KB Output is correct
61 Correct 421 ms 71412 KB Output is correct
62 Correct 455 ms 71704 KB Output is correct
63 Correct 443 ms 71620 KB Output is correct
64 Correct 537 ms 71708 KB Output is correct
65 Correct 447 ms 71608 KB Output is correct
66 Correct 451 ms 71580 KB Output is correct
67 Correct 451 ms 71704 KB Output is correct
68 Correct 482 ms 71548 KB Output is correct