-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatching.cpp
More file actions
37 lines (35 loc) · 837 Bytes
/
matching.cpp
File metadata and controls
37 lines (35 loc) · 837 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
int n,q;
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
cin >> q;
vector<int> ppp;
vector<pair<int,int>> price;
vector<int> ans;
for (int i=1;i<=n;i++){
int m;
cin >> m;
ppp.push_back(m);
price.push_back(make_pair(m,i));
}
sort(price.begin(),price.end());
for (int i=0;i<q;i++){
int x,y,xp,aa;
cin >> x;
cin >> y;
xp = ppp[x-1];
aa = xp+y;
for (int j=0;j<n;j++){
if (aa == price[j].first) {ans.push_back(price[j].second); break;}
else if (aa < price[j].first) {ans.push_back((price[j].second)-1); break;}
}
}
for (int i=0;i<q;i++){
cout << ans[i] << "\n";
}
}