답안 #643144

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
643144 2022-09-21T10:00:18 Z kith14 Fountain (eJOI20_fountain) C++17
60 / 100
249 ms 6252 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define db double
#define pairll pair<ll,ll>
#define lpairll pair<ll,pairll>

#define repp(i,a,b) for (ll i = a; i <= b; i++)
#define repz(i,a,b) for (ll i = a; i < b; i++)
#define repm(i,a,b) for (ll i = a; i >= b; i--)
#define fr first
#define sc second
#define mp make_pair
#define pb push_back

const ll N = 1e5+5, MOD = 1e9+7, M = 2e2+5;
ll tc = 1, n, m, dr[N], vr[N];
ll x, y, k, pr[N];
string s, s1, s2, ye = "YES", no = "NO";
vector<ll> tt, v;

void input(){
  cin >> n >> m;
  repp(i,1,n) cin >> dr[i] >> vr[i];
}

void sb1(){
  while(m--){
    cin >> x >> y;
    ll pre = 0;
    repp(i,x,n){
      if (pre < dr[i]){
        pre = dr[i];
        y -= vr[i];
        if (y <= 0){
          cout << i << endl;
          break;
        }
      }
    }
    if (y > 0) cout << "0" << endl;
  }
}

void sb2(){
  repp(i,1,n){
    pr[i] = pr[i-1]+vr[i];
  }
  while(m--){
    cin >> x >> y;
    ll l = x, r = n, ret = 0;
    while (l <= r){
      ll md = (l+r)/2;
      if (pr[md]-pr[x-1] >= y){
        ret = md;
        r = md-1;
      }
      else l = md+1;
    }
    cout << ret << endl;
  } 
}

void solve(){
  if (n <= 1000){
    sb1();
  }
  else sb2();
}

int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  //cin >> tc;
  while(tc--){
    input();
    solve();
  }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 2 ms 336 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 3 ms 340 KB Output is correct
5 Correct 5 ms 336 KB Output is correct
6 Correct 4 ms 340 KB Output is correct
7 Correct 5 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 208 ms 6152 KB Output is correct
2 Correct 249 ms 6252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 2 ms 336 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 3 ms 340 KB Output is correct
5 Correct 5 ms 336 KB Output is correct
6 Correct 4 ms 340 KB Output is correct
7 Correct 5 ms 340 KB Output is correct
8 Correct 208 ms 6152 KB Output is correct
9 Correct 249 ms 6252 KB Output is correct
10 Incorrect 5 ms 340 KB Output isn't correct
11 Halted 0 ms 0 KB -