# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
464817 | Alen777 | Fountain (eJOI20_fountain) | C++14 | 1176 ms | 524292 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <string>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <algorithm>
#include <cstring>
using namespace std;
#define ll long long
#define ull unsigned ll
#define pb push_back
#define mpr make_pair
#define lb lower_bound
#define ld long double
#define ub upper_bound
const int N = 100005;
int c[N], d[N];
vector<pair<int, int> > cnt[N];
void solve() {
int n, q;
cin >> n >> q;
for (int i = 0; i < n; i++) {
cin >> d[i] >> c[i];
}
for (int i = 0; i < n; i++) {
cnt[i].push_back(mpr(c[i], i));
int ind = i;
long long tar = c[i];
for (int j = i + 1; j < n; j++) {
if (d[j] > d[ind]) {
tar += c[j];
ind = j;
cnt[i].push_back(mpr(tar, ind));
}
}
}
while (q--) {
int ind, tar;
cin >> ind >> tar;
ind--;
int ind0 = lower_bound(cnt[ind].begin(), cnt[ind].end(), mpr(tar, 0)) - cnt[ind].begin();
if (ind0 == cnt[ind].size()) {
cout << 0 << endl;
continue;
}
cout << cnt[ind][ind0].second + 1 << endl;
}
}
int main() {
/*cout.setf(ios::fixed | ios::showpoint);
cout.precision(6);*/
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
solve();
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |