Submission #576418

# Submission time Handle Problem Language Result Execution time Memory
576418 2022-06-13T05:47:48 Z emad234 Fountain (eJOI20_fountain) C++17
30 / 100
64 ms 2004 KB
#include <bits/stdc++.h>
#define all(v) ((v).begin(),(v).end())
typedef long long ll;
using namespace std;
const int mod = 1e9 + 7;
const int mxN = 2e6 + 1;
pair<int,int> a[mxN];
int prfx[mxN];
int main()
{
  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  int n,q;
  cin >>n>>q;
  for(int i = 1;i <= n;i++){
    cin >>a[i].first>>a[i].second;
  }
  a[n + 1].first = INT_MAX;a[n + 1].second = INT_MAX;
  for(int i = 1;i <= n + 1;i++){
    prfx[i] = prfx[i - 1] + a[i].first;
  }
  while(q--){
    int r,v;
    cin >>r>>v;
    if(n <= 1000 && q <= 2000){
      int prev = a[r].first - 1;
      for(int i = r;i <= n + 1;i++){
        if(a[i].first > prev){
          prev = a[i].first;
          v -= a[i].second;
        }
        if(v <= 0){
          if(i == n + 1)
            cout<<0<<'\n';
          else
            cout <<i<<'\n';
          break;
        }
      }
    }else{
      int x = lower_bound(prfx,prfx + n + 1,v + prfx[r - 1]) - prfx;
      if(x == n + 1)
        cout<<0<<'\n';
      else
        cout<<x<<'\n';
    }
  }
}































//                                                                  nice
# Verdict Execution time Memory Grader output
1 Correct 0 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 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 64 ms 2004 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 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 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Incorrect 64 ms 2004 KB Output isn't correct
9 Halted 0 ms 0 KB -