//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include<bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define pb push_back
#define pf push_front
#define ppb pop_back
#define forik(x) ll i = 1; i <= x; i++
const int mod = 1e9 + 7;
using namespace std;
ll n, q, d[100001], c[100001], idx, z, a, b, e, pr[100001], l, r, m, w;
ll gcd (ll a, ll b){
while (a > 0 && b > 0){
if (a >= b){
a %= b;
}
else{
b %= a;
}
}
return a + b;
}
ll binpow(ll a, ll b){
a %= mod;
if(b == 0){
return 1;
}
if(b % 2 == 1){
return binpow (a, b - 1) % mod * a;
}
if(b % 2 == 0){
ll t = binpow(a, b / 2) % mod;
return t * t % mod;
}
}
signed main (){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> q;
for (int i = 1; i <= n; i++){
cin >> d[i] >> c[i];
pr[i] = pr[i - 1] + c[i];
}
for (int i = 1; i < n; i++){
if (d[i] < d[i + 1]){
a++;
}
}
if (a == n - 1){
while (q--){
cin >> idx >> z;
if (pr[n] - pr[idx - 1] < z){
cout << 0 << '\n';
}
else{
l = idx;
r = n;
while (l <= r){
m = (l + r) / 2;
if (pr[m] - pr[idx - 1] < z){
l = m + 1;
}
else{
r = m - 1;
}
}
cout << l << '\n';
}
}
}
else{
while (q--){
cin >> idx >> r;
a = 0;
b = 0;
for (int i = idx; i <= n; i++){
if (d[i] > a){
r -= c[i];
a = d[i];
}
if (r <= 0){
b = i;
break;
}
}
cout << b << '\n';
}
}
}
Compilation message
fountain.cpp: In function 'long long int binpow(long long int, long long int)':
fountain.cpp:42:1: warning: control reaches end of non-void function [-Wreturn-type]
42 | }
| ^
# |
Verdict |
Execution time |
Memory |
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 |
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 |
Correct |
53 ms |
3240 KB |
Output is correct |
2 |
Correct |
70 ms |
3144 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
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 |
53 ms |
3240 KB |
Output is correct |
9 |
Correct |
70 ms |
3144 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Execution timed out |
1587 ms |
1916 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |