Submission #506143

# Submission time Handle Problem Language Result Execution time Memory
506143 2022-01-11T17:34:20 Z lucri Art Exhibition (JOI18_art) C++14
100 / 100
534 ms 24224 KB
#include <iostream>
#include <algorithm>
using namespace std;
long long s,n,r,ss[500010],sd[500010],r2;
struct tablouri{long long a,b;}t[500010];
bool comp(tablouri a1,tablouri b1)
{
    return a1.a<b1.a;
}
int main()
{
    cin>>n;
    for(long long i=1;i<=n;++i)
    {
        cin>>t[i].a>>t[i].b;
        s+=t[i].b;
    }
    sort(t+1,t+n+1,comp);
    r=s-t[n].a+t[1].a;
    long long sp=0;
    for(long long i=2;i<=n;++i)
    {
        sp+=t[i-1].b;
        ss[i]=t[i].a-sp-t[1].a;
        ss[i]=max(ss[i-1],ss[i]);
    }
    sp=0;
    for(long long i=n-1;i>=1;--i)
    {
        sp+=t[i+1].b;
        sd[i]=t[n].a-sp-t[i].a;
        sd[i]=max(sd[i],sd[i+1]);
    }
    for(long long i=1;i<=n;++i)
        r2=max(r2,sd[i]+ss[i]);
    cout<<r+r2;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 292 KB Output is correct
3 Correct 0 ms 304 KB Output is correct
4 Correct 0 ms 292 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 0 ms 204 KB Output is correct
9 Correct 0 ms 308 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 292 KB Output is correct
3 Correct 0 ms 304 KB Output is correct
4 Correct 0 ms 292 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 0 ms 204 KB Output is correct
9 Correct 0 ms 308 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 308 KB Output is correct
13 Correct 1 ms 332 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 304 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 1 ms 312 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 304 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 0 ms 292 KB Output is correct
3 Correct 0 ms 304 KB Output is correct
4 Correct 0 ms 292 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 0 ms 204 KB Output is correct
9 Correct 0 ms 308 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 308 KB Output is correct
13 Correct 1 ms 332 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 304 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 1 ms 312 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 304 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 6 ms 560 KB Output is correct
28 Correct 5 ms 564 KB Output is correct
29 Correct 5 ms 564 KB Output is correct
30 Correct 5 ms 528 KB Output is correct
31 Correct 5 ms 580 KB Output is correct
32 Correct 6 ms 568 KB Output is correct
33 Correct 7 ms 580 KB Output is correct
34 Correct 6 ms 572 KB Output is correct
35 Correct 5 ms 572 KB Output is correct
36 Correct 5 ms 552 KB Output is correct
37 Correct 5 ms 568 KB Output is correct
38 Correct 6 ms 548 KB Output is correct
39 Correct 6 ms 564 KB Output is correct
40 Correct 6 ms 564 KB Output is correct
41 Correct 6 ms 588 KB Output is correct
42 Correct 6 ms 548 KB Output is correct
43 Correct 5 ms 588 KB Output is correct
44 Correct 5 ms 576 KB Output is correct
45 Correct 6 ms 588 KB Output is correct
46 Correct 6 ms 568 KB Output is correct
47 Correct 5 ms 560 KB Output is correct
48 Correct 6 ms 588 KB Output is correct
49 Correct 5 ms 576 KB Output is correct
50 Correct 6 ms 584 KB Output is correct
51 Correct 5 ms 588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 292 KB Output is correct
3 Correct 0 ms 304 KB Output is correct
4 Correct 0 ms 292 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 0 ms 204 KB Output is correct
9 Correct 0 ms 308 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 308 KB Output is correct
13 Correct 1 ms 332 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 304 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 1 ms 312 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 304 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 6 ms 560 KB Output is correct
28 Correct 5 ms 564 KB Output is correct
29 Correct 5 ms 564 KB Output is correct
30 Correct 5 ms 528 KB Output is correct
31 Correct 5 ms 580 KB Output is correct
32 Correct 6 ms 568 KB Output is correct
33 Correct 7 ms 580 KB Output is correct
34 Correct 6 ms 572 KB Output is correct
35 Correct 5 ms 572 KB Output is correct
36 Correct 5 ms 552 KB Output is correct
37 Correct 5 ms 568 KB Output is correct
38 Correct 6 ms 548 KB Output is correct
39 Correct 6 ms 564 KB Output is correct
40 Correct 6 ms 564 KB Output is correct
41 Correct 6 ms 588 KB Output is correct
42 Correct 6 ms 548 KB Output is correct
43 Correct 5 ms 588 KB Output is correct
44 Correct 5 ms 576 KB Output is correct
45 Correct 6 ms 588 KB Output is correct
46 Correct 6 ms 568 KB Output is correct
47 Correct 5 ms 560 KB Output is correct
48 Correct 6 ms 588 KB Output is correct
49 Correct 5 ms 576 KB Output is correct
50 Correct 6 ms 584 KB Output is correct
51 Correct 5 ms 588 KB Output is correct
52 Correct 506 ms 24224 KB Output is correct
53 Correct 503 ms 21596 KB Output is correct
54 Correct 534 ms 21564 KB Output is correct
55 Correct 496 ms 21600 KB Output is correct
56 Correct 505 ms 21604 KB Output is correct
57 Correct 518 ms 21640 KB Output is correct
58 Correct 501 ms 21580 KB Output is correct
59 Correct 520 ms 21548 KB Output is correct
60 Correct 498 ms 21580 KB Output is correct
61 Correct 491 ms 21596 KB Output is correct
62 Correct 497 ms 21636 KB Output is correct
63 Correct 497 ms 21572 KB Output is correct
64 Correct 504 ms 21532 KB Output is correct
65 Correct 498 ms 21260 KB Output is correct
66 Correct 505 ms 21260 KB Output is correct
67 Correct 490 ms 21264 KB Output is correct
68 Correct 508 ms 21276 KB Output is correct