이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll, ll>
void print(ll Z) {
cout << Z << endl;
}
struct threeVar {
ll first, second, third;
};
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll N, Q;
cin >> N >> Q;
pll arr[N+4];
vector<threeVar> V[N+2];
for(int i=1; i<=N; i++) {
cin >> arr[i].first >> arr[i].second;
V[i].push_back({arr[i].first, arr[i].second, i});
for(int j=1; j<i; j++) {
if(arr[i].first > V[j].back().first) {
if(!V[j].empty()) {
V[j].push_back({arr[i].first, V[j].back().second + arr[i].second, i});
}
}
}
}
while(Q--) {
ll X, Y;
cin >> X >> Y;
if(!V[X].empty()) {
ll Z = V[X].back().second;
if(Y > Z) {
print(0);
}
else {
ll ans = V[X][0].third;
bool firstTime = 1;
for(auto i: V[X]) {
if(i.second < Y) {
ans = i.third;
}
else if(i.second == Y) {
ans = i.third;
break;
}
else {
if(firstTime) {
firstTime = 0;
ans = i.third;
}
else {break;}
}
}
print(ans);
}
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |