-
Notifications
You must be signed in to change notification settings - Fork 1
/
momosMarket.cpp
40 lines (32 loc) · 896 Bytes
/
momosMarket.cpp
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
38
39
40
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
int *prices = new int[n];
// vector<pair<int, int>> prices;
int price;
for(int i = 0; i < n; i++){
cin >> prices[i];
// prices.push_back( make_pair(price, i));
}
int q;
cin >> q;
int *savings = new int[q];
for(int i = 0; i < q; i++){
cin >> savings[i];
}
for(int i = 1; i < n; i++){
prices[i] += prices[i-1];
}
for(int i = 0; i < q; i++){
int momos = upper_bound(prices, prices + n, savings[i]) - prices;
// cout << prices[momos].first << " " << prices[momos].second << endl;
// cout << momos->second << " " << savings[i] - momos->first << endl;
cout << momos << " " << savings[i] - prices[momos-1] << endl;
}
delete [] savings;
delete [] prices;
return 0;
}