답안 #776352

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
776352 2023-07-07T17:45:49 Z LeVanThuc Art Exhibition (JOI18_art) C++17
100 / 100
252 ms 29440 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define p(x,y) pair<ll,ll>(x,y)
#define BIT(i,x) ((x>>i)&1)
#define MASK(x) (1<<x)
#define ld long double
#define __builtin_popcount __builtin_popcountll
#define pll pair<ll,ll>
template<class T1,class T2>
bool maximize(T1 &x,const T2 &y)
{
    if(x<y)
    {
        x=y;
        return 1;
    }
    return 0;
}
template<class T1,class T2>
bool minimize(T1 &x,const T2 &y)
{
    if(x>y)
    {
        x=y;
        return 1;
    }
    return 0;
}
void online()
{
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
}
const ll M=1e16;
struct SegmentTree
{
    vector<ll> Tree;
    ll n;
    SegmentTree(ll _n=0)
    {
        n=_n;
        Tree.resize(4*n+1);
    }
    ll update(ll i,ll l,ll r,ll pos,ll vl)
    {
        if(r<pos||pos<l) return Tree[i];
        if(l==r) return Tree[i]=vl;
        return Tree[i]=min(update(i*2,l,(l+r)/2,pos,vl),update(i*2+1,(l+r)/2+1,r,pos,vl));
    }
    ll query(ll i,ll l,ll r,ll u,ll v)
    {
        if(v<l||r<u) return M;
        if(u<=l&&r<=v) return Tree[i];
        return min(query(i*2,l,(l+r)/2,u,v),query(i*2+1,(l+r)/2+1,r,u,v));
    }
};
const ll N=5e5+10;
ll n,f[N];
pll a[N];
int main()
{
    online();
    cin>>n;
    SegmentTree S(n);
    for(int i=1;i<=n;i++)
    {
        cin>>a[i].fi>>a[i].se;
    }
    sort(a+1,a+n+1);
    ll ans=0;
    for(int i=1;i<=n;i++)
    {
        a[i].se+=a[i-1].se;
        S.update(1,1,n,i,a[i-1].se-a[i].fi);
        f[i]=a[i].se-a[i].fi+a[1].fi;
        maximize(f[i],a[i].se-a[i].fi-S.query(1,1,n,1,i));
        maximize(ans,f[i]);
    }
    cout<<ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 324 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 312 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
11 Correct 1 ms 328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 324 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 312 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
11 Correct 1 ms 328 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 328 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 328 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 324 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 312 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
11 Correct 1 ms 328 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 328 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 328 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 2 ms 724 KB Output is correct
28 Correct 2 ms 724 KB Output is correct
29 Correct 3 ms 724 KB Output is correct
30 Correct 2 ms 724 KB Output is correct
31 Correct 3 ms 724 KB Output is correct
32 Correct 3 ms 748 KB Output is correct
33 Correct 2 ms 724 KB Output is correct
34 Correct 3 ms 720 KB Output is correct
35 Correct 3 ms 724 KB Output is correct
36 Correct 3 ms 724 KB Output is correct
37 Correct 4 ms 744 KB Output is correct
38 Correct 2 ms 724 KB Output is correct
39 Correct 2 ms 724 KB Output is correct
40 Correct 2 ms 724 KB Output is correct
41 Correct 2 ms 724 KB Output is correct
42 Correct 2 ms 720 KB Output is correct
43 Correct 2 ms 744 KB Output is correct
44 Correct 3 ms 724 KB Output is correct
45 Correct 2 ms 744 KB Output is correct
46 Correct 2 ms 720 KB Output is correct
47 Correct 3 ms 648 KB Output is correct
48 Correct 2 ms 724 KB Output is correct
49 Correct 2 ms 724 KB Output is correct
50 Correct 2 ms 724 KB Output is correct
51 Correct 2 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 324 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 312 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
11 Correct 1 ms 328 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 328 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 328 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 2 ms 724 KB Output is correct
28 Correct 2 ms 724 KB Output is correct
29 Correct 3 ms 724 KB Output is correct
30 Correct 2 ms 724 KB Output is correct
31 Correct 3 ms 724 KB Output is correct
32 Correct 3 ms 748 KB Output is correct
33 Correct 2 ms 724 KB Output is correct
34 Correct 3 ms 720 KB Output is correct
35 Correct 3 ms 724 KB Output is correct
36 Correct 3 ms 724 KB Output is correct
37 Correct 4 ms 744 KB Output is correct
38 Correct 2 ms 724 KB Output is correct
39 Correct 2 ms 724 KB Output is correct
40 Correct 2 ms 724 KB Output is correct
41 Correct 2 ms 724 KB Output is correct
42 Correct 2 ms 720 KB Output is correct
43 Correct 2 ms 744 KB Output is correct
44 Correct 3 ms 724 KB Output is correct
45 Correct 2 ms 744 KB Output is correct
46 Correct 2 ms 720 KB Output is correct
47 Correct 3 ms 648 KB Output is correct
48 Correct 2 ms 724 KB Output is correct
49 Correct 2 ms 724 KB Output is correct
50 Correct 2 ms 724 KB Output is correct
51 Correct 2 ms 724 KB Output is correct
52 Correct 238 ms 29336 KB Output is correct
53 Correct 231 ms 29300 KB Output is correct
54 Correct 236 ms 29388 KB Output is correct
55 Correct 227 ms 29344 KB Output is correct
56 Correct 224 ms 29388 KB Output is correct
57 Correct 232 ms 29344 KB Output is correct
58 Correct 227 ms 29388 KB Output is correct
59 Correct 249 ms 29300 KB Output is correct
60 Correct 252 ms 29336 KB Output is correct
61 Correct 227 ms 29440 KB Output is correct
62 Correct 231 ms 29364 KB Output is correct
63 Correct 227 ms 29380 KB Output is correct
64 Correct 231 ms 29360 KB Output is correct
65 Correct 225 ms 29276 KB Output is correct
66 Correct 229 ms 29260 KB Output is correct
67 Correct 235 ms 29312 KB Output is correct
68 Correct 227 ms 29336 KB Output is correct