답안 #90612

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
90612 2018-12-22T22:25:47 Z Harvey_Rollens 금 캐기 (IZhO14_divide) C++17
0 / 100
82 ms 3068 KB
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define st string
#define fr first
#define se second

const ll mod=1e9+7;

using namespace std;

ll p[100100], s[100100], n, ans=0, a[100100];

bool divide(ll x)
{
    ll l=1, r=1;
    while(a[r+1]-a[l]<=x && r+1<=n)
        r++;

    ll k=0;

    //cout<<x<<" "<<l<<" "<<r<<endl;
    while(l<=n)
    {
        while(a[r+1]-a[l]<=x && r+1<=n)
            r++;

        //cout<<x<<" "<<l<<" "<<r<<endl;

        ll ener=p[r]-p[l-1];
        if(ener>=x)
        {
            k++;
            ll gold=s[r]-s[l-1];
            ans=max(ans, gold);
        }

        l++;
    }
    l=n, r=n;
    while(a[l]-a[r-1]<=x && r-1>=1)
        r--;

    //cout<<x<<" "<<l<<" "<<r<<endl;
    while(l>0)
    {
        while(a[l]-a[r-1]<=x && r-1>=1)
        r--;

        //cout<<x<<" "<<l<<" "<<r<<endl;

        ll ener=p[l]-p[r-1];
        if(ener>=x)
        {
            k++;
            ll gold=s[l]-s[r-1];
            ans=max(ans, gold);
        }

        l--;
    }

    if(k) return true;
    else return false;
}

int main()
{
    //freopen("1.txt", "r", stdin);
    //freopen("1.txt", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);

    cin>>n;

    for(ll i=1; i<=n; i++)
    {
        ll g, e;
        cin>>a[i]>>g>>e;

        p[i]=e+p[i-1];
        s[i]=g+s[i-1];
    }

    ll l=0, r=1e9+1;
    while(l+1<r)
    {
        //cout<<l<<" "<<r<<endl;
        ll d=(l+r)/2;

        if(divide(d)) l=d;
        else r=d;
    }

    //cout<<l<<" "<<r<<endl;

    cout<<ans;
    return 0;
}
/*
4 6 3
1 2 1
2 4 1
2 3 2
3 1 4
1 4 3
3 4 10
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 408 KB Output is correct
4 Incorrect 2 ms 484 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 560 KB Output is correct
2 Correct 2 ms 560 KB Output is correct
3 Incorrect 2 ms 560 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 688 KB Output is correct
2 Correct 5 ms 816 KB Output is correct
3 Correct 6 ms 1004 KB Output is correct
4 Correct 25 ms 1788 KB Output is correct
5 Correct 27 ms 1788 KB Output is correct
6 Correct 54 ms 2940 KB Output is correct
7 Correct 46 ms 2940 KB Output is correct
8 Correct 46 ms 3068 KB Output is correct
9 Correct 41 ms 3068 KB Output is correct
10 Correct 82 ms 3068 KB Output is correct
11 Incorrect 75 ms 3068 KB Output isn't correct
12 Halted 0 ms 0 KB -