답안 #576482

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
576482 2022-06-13T06:32:23 Z MrM7md Fountain (eJOI20_fountain) C++17
60 / 100
72 ms 3228 KB
#include <bits/stdc++.h>

using namespace std;
#define int long long
#define endl "\n"

const int MOD = 1e9 + 7;

pair<int,int> a[10000000];
signed main(){
   ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
   int n,q;
   cin >> n>>q;
   int pref[n+1]={0};
   for(int i=0;i<n;i++){
      cin >> a[i].first>>a[i].second;
      pref[i+1]=a[i].second;
      pref[i+1]+=pref[i];
   }
   pref[n]=a[n-1].second;
   pref[n]+=pref[n-1];
   a[n]={INT_MAX,INT_MAX};
   if(n<=1000&&q<=2000){   
      while(q--){
         int r,v;
         cin >>r >> v;
         int cur=a[r-1].first;
         v-=a[r-1].second;
         int ans=r-1;
         for(int i=r;i<=n;i++){
            if(a[i].first>cur){
               if(v<=0) {
                  break;
               }
               ans=i;
               cur=a[i].first;
               v-=a[i].second;
            }
         }

         if(ans==n)ans=-1;
         cout<<ans+1<<endl;
      }
   }
   else{
      while(q--){
      int r,v;
      cin >>r >> v;
      v+=pref[r-1];
      int ans=lower_bound(pref,pref+n,v)-pref;
      if(v>pref[ans+1])ans++;
      if(ans==n)ans=0;
      cout<<ans<<endl;
   }
   }

}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 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 2 ms 340 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 61 ms 3188 KB Output is correct
2 Correct 72 ms 3228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 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 2 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 61 ms 3188 KB Output is correct
9 Correct 72 ms 3228 KB Output is correct
10 Incorrect 1 ms 340 KB Output isn't correct
11 Halted 0 ms 0 KB -