답안 #1024710

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1024710 2024-07-16T09:30:38 Z vjudge1 Fountain (eJOI20_fountain) C++17
0 / 100
177 ms 4000 KB
#include <bits/stdc++.h>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, q;
    cin>>n>>q;
    long long int d[n], c[n], prefix_sum[n+1];
    bool subtask1=0;
    prefix_sum[n]=INT_MAX;
    for(int i=0; i<n; i++)
    {
        cin>>d[i]>>c[i];
        if(i>1 && d[i-1]>=d[i])
        {
            subtask1=1;
        }
        prefix_sum[i]=c[i];
        if(i>=1)
        {
            prefix_sum[i]+=prefix_sum[i-1];
        }
    }
    if(subtask1)
    {
        while(q--)
        {
            long long int nivo, voda;
            cin>>nivo>>voda;
            long long int curr=nivo, prev=d[nivo-1];
            voda-=c[nivo-1];
            bool kiki=0;
            for(int i=nivo; i<n; i++)
            {
                if(d[i]>prev && voda>0)
                {
                    prev=d[i];
                    voda-=c[i];
                    curr=i+1;
                }
                if(voda<=0)
                {
                    kiki=1;
                }
            }
            if(kiki)
                cout<<curr<<"\n";
            else
                cout<<0<<"\n";
        }
    }
    else                            //subtask2
    {
        while(q--)
        {
            long long int nivo, voda, rez=nivo;
            cin>>nivo>>voda;
            int l=nivo-1, r=n;
            while(r-l>1)
            {
                int mid=(l+r)/2;
                long long int aa=0;
                if(nivo==1)
                    aa=0;
                else
                    aa=prefix_sum[nivo-2];
                if(prefix_sum[mid]-aa>=voda)
                {
                    r=mid;
                }
                else
                {
                    l=mid;
                }
            }
            rez=r;
            if(rez==n)
                cout<<"0\n";
            else
                cout<<rez+1<<"\n";
            cout.flush();
        }
    }
    

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Incorrect 3 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 177 ms 4000 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Incorrect 3 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -