Submission #492827

# Submission time Handle Problem Language Result Execution time Memory
492827 2021-12-09T06:35:02 Z Karabasan Art Exhibition (JOI18_art) C++17
100 / 100
184 ms 24820 KB
#include <bits/stdc++.h>
#define ll long long
#define fast1 ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define int long long
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("fma,sse,sse2,sse3,avx")
#pragma GCC optimize("unroll-loops")

int n;
pair<int,int> p[500005];
int pre[500005];
void solve()
{
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>p[i].first>>p[i].second;
    sort(p+1,p+n+1);
    pre[1]=p[1].second;
    for(int i=2;i<=n;i++)
        pre[i]=pre[i-1]+p[i].second;
    int mn=p[1].first;
    int mx=p[1].first;
    int val=p[1].second;
    int cvp=p[1].second;
    int ind=1;
    for(int i=2;i<=n;i++)
    {
        while(p[i].first-mn>pre[i-1]-pre[ind-1]&&ind<i)
        {
            mn=p[ind+1].first;
            ind++;
        }
        cvp=max(cvp,pre[i]-pre[ind-1]-p[i].first+mn);
    }
    cout<<cvp;

}
signed main()
{
    fast1
    //freopen ("lca.gir","r",stdin);
    //freopen ("lca.cik","w",stdout);
    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}

Compilation message

art.cpp: In function 'void solve()':
art.cpp:24:9: warning: unused variable 'mx' [-Wunused-variable]
   24 |     int mx=p[1].first;
      |         ^~
art.cpp:25:9: warning: unused variable 'val' [-Wunused-variable]
   25 |     int val=p[1].second;
      |         ^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 324 KB Output is correct
14 Correct 1 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 1 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 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 324 KB Output is correct
14 Correct 1 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 1 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 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 2 ms 460 KB Output is correct
28 Correct 2 ms 460 KB Output is correct
29 Correct 2 ms 460 KB Output is correct
30 Correct 3 ms 460 KB Output is correct
31 Correct 3 ms 460 KB Output is correct
32 Correct 2 ms 460 KB Output is correct
33 Correct 2 ms 460 KB Output is correct
34 Correct 3 ms 460 KB Output is correct
35 Correct 2 ms 460 KB Output is correct
36 Correct 2 ms 460 KB Output is correct
37 Correct 2 ms 460 KB Output is correct
38 Correct 2 ms 460 KB Output is correct
39 Correct 2 ms 460 KB Output is correct
40 Correct 2 ms 496 KB Output is correct
41 Correct 3 ms 460 KB Output is correct
42 Correct 2 ms 460 KB Output is correct
43 Correct 2 ms 464 KB Output is correct
44 Correct 2 ms 460 KB Output is correct
45 Correct 2 ms 460 KB Output is correct
46 Correct 3 ms 460 KB Output is correct
47 Correct 2 ms 460 KB Output is correct
48 Correct 2 ms 460 KB Output is correct
49 Correct 2 ms 460 KB Output is correct
50 Correct 2 ms 460 KB Output is correct
51 Correct 2 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 324 KB Output is correct
14 Correct 1 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 1 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 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 2 ms 460 KB Output is correct
28 Correct 2 ms 460 KB Output is correct
29 Correct 2 ms 460 KB Output is correct
30 Correct 3 ms 460 KB Output is correct
31 Correct 3 ms 460 KB Output is correct
32 Correct 2 ms 460 KB Output is correct
33 Correct 2 ms 460 KB Output is correct
34 Correct 3 ms 460 KB Output is correct
35 Correct 2 ms 460 KB Output is correct
36 Correct 2 ms 460 KB Output is correct
37 Correct 2 ms 460 KB Output is correct
38 Correct 2 ms 460 KB Output is correct
39 Correct 2 ms 460 KB Output is correct
40 Correct 2 ms 496 KB Output is correct
41 Correct 3 ms 460 KB Output is correct
42 Correct 2 ms 460 KB Output is correct
43 Correct 2 ms 464 KB Output is correct
44 Correct 2 ms 460 KB Output is correct
45 Correct 2 ms 460 KB Output is correct
46 Correct 3 ms 460 KB Output is correct
47 Correct 2 ms 460 KB Output is correct
48 Correct 2 ms 460 KB Output is correct
49 Correct 2 ms 460 KB Output is correct
50 Correct 2 ms 460 KB Output is correct
51 Correct 2 ms 460 KB Output is correct
52 Correct 178 ms 24560 KB Output is correct
53 Correct 170 ms 24644 KB Output is correct
54 Correct 172 ms 24648 KB Output is correct
55 Correct 171 ms 24668 KB Output is correct
56 Correct 170 ms 24592 KB Output is correct
57 Correct 168 ms 24668 KB Output is correct
58 Correct 172 ms 24668 KB Output is correct
59 Correct 169 ms 24632 KB Output is correct
60 Correct 163 ms 24612 KB Output is correct
61 Correct 176 ms 24488 KB Output is correct
62 Correct 167 ms 24640 KB Output is correct
63 Correct 179 ms 24620 KB Output is correct
64 Correct 184 ms 24744 KB Output is correct
65 Correct 169 ms 24560 KB Output is correct
66 Correct 178 ms 24680 KB Output is correct
67 Correct 168 ms 24604 KB Output is correct
68 Correct 171 ms 24820 KB Output is correct