-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLetters.cpp
More file actions
34 lines (29 loc) · 776 Bytes
/
Letters.cpp
File metadata and controls
34 lines (29 loc) · 776 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
/** https://codeforces.com/problemset/problem/978/C
* #binary-search #two-pointer
*/
#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;
int main() {
int n, m;
cin >> n >> m;
vector<ll> arr(n+1);
ll roomsInDormitory;
for (int i=1; i < n+1; i++) {
cin >> roomsInDormitory;
arr[i] = roomsInDormitory;
}
int dormitoryIdx = 0;
ll allRoomsToDormitory = 0;
ll roomIdx;
for (int i=0; i < m; i++) {
cin >> roomIdx;
while(roomIdx > allRoomsToDormitory) {
dormitoryIdx++;
allRoomsToDormitory += arr[dormitoryIdx];
}
cout << dormitoryIdx << " " << roomIdx - (allRoomsToDormitory - arr[dormitoryIdx])<< endl;
}
return 0;
}