답안 #657304

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
657304 2022-11-09T13:14:38 Z Banan Fountain (eJOI20_fountain) C++17
60 / 100
1500 ms 5016 KB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
#define int long long
#define double long double
#define endl '\n'
#define sz(a) (int)a.size()
#define pb push_back
#define fs first
#define sc second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
int const INF = LONG_LONG_MAX;

int n, q, d[200005], c[200005];

void solve()
{
    cin>>n>>q;
    for(int i=1;i<=n;i++)
    {
        cin>>d[i]>>c[i];
    }
    vector<int> pref(n+5, 0);
    bool ca=1;
    for(int i=2;i<=n;i++)
    {
        if(d[i]<=d[i-1]){ca=0;}
    }
    d[n+1]=INF;
    c[n+1]=INF;
    if(ca)
    {
        for(int i=1;i<=n;i++)
        {
            pref[i]=pref[i-1]+c[i];
        }
        pref[n+1]=INF;
        while(q--)
        {
            int r, v;
            cin>>r>>v;
            int lo=r, hi=n+1, mid=(lo+hi)/2, ans;
            while(lo<=hi)
            {
                if(pref[mid]-pref[r-1]>=v){ans=mid;hi=mid-1;mid=(lo+hi)/2;}
                else{lo=mid+1;mid=(lo+hi)/2;}
            }
            if(ans>n){cout<<0<<endl;}else{cout<<ans<<endl;}
        }
    }
    else
    {
        while(q--)
        {
            int r, v;
            cin>>r>>v;
            bool b=1;
            while(v-c[r]>0)
            {
                v-=c[r];
                int k=1;
                while(d[r]>=d[r+k])
                {
                    k++;
                }
                r+=k;
                if(r>n){b=0;break;}
            }
            if(b){cout<<r<<endl;}else{cout<<0<<endl;}
        }
    }
}

int32_t main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int tc=1;
    //cin>>tc;
    while(tc--)
    {
        solve();
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 65 ms 3816 KB Output is correct
2 Correct 68 ms 5016 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 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 65 ms 3816 KB Output is correct
9 Correct 68 ms 5016 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Execution timed out 1582 ms 3532 KB Time limit exceeded
12 Halted 0 ms 0 KB -