//#include <bits/stdc++.h>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <fstream>
#include <unordered_map>
using namespace std;
#define int long long
#define pb push_back
#define S second
#define F first
const int N = 2e5 + 5;
const int INF = 1e18 - 1;
const int MOD = 1e9 + 7;
int n, d[N], v[N];
int q, p[N];
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> q;
int ok = 0;
for (int i = 1; i <= n; ++ i) {
cin >> d[i] >> v[i];
if (d[i] <= d[i - 1]) ok = 1;
p[i] = p[i - 1] + v[i];
}
if (!ok) {
while (q --) {
int st, vl, res = 0;
cin >> st >> vl;
int l = st, r = n;
if (p[n] - p[st - 1] < vl) {
cout << "0\n";
continue;
}
while (l <= r) {
int mid = (l + r) >> 1;
if (p[mid] - p[st - 1] >= vl) r = mid - 1, res = mid;
else l = mid + 1;
}
cout << res << '\n';
}
return 0;
}
while (q --) {
int r, vl;
cin >> r >> vl;
int mx = -1, got = 0, res = 0;
for (int i = r; i <= n; ++ i) {
if (mx < d[i]) {
mx = d[i];
got += v[i];
if (got >= vl) {
res = i;
break;
}
}
}
cout << res << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 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 |
68 ms |
4120 KB |
Output is correct |
2 |
Correct |
69 ms |
6324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 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 |
68 ms |
4120 KB |
Output is correct |
9 |
Correct |
69 ms |
6324 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Execution timed out |
1580 ms |
3272 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |