CF978C.Letters
入门
通过率:0%
时间限制:4.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There are n dormitories in Berland State University, they are numbered with integers from 1 to n. Each dormitory consists of rooms, there are ai rooms in i-th dormitory. The rooms in i-th dormitory are numbered from 1 to ai.
A postman delivers letters. Sometimes there is no specific dormitory and room number in it on an envelope. Instead of it only a room number among all rooms of all n dormitories is written on an envelope. In this case, assume that all the rooms are numbered from 1 to a1+a2+⋯+an and the rooms of the first dormitory go first, the rooms of the second dormitory go after them and so on.
For example, in case n=2, a1=3 and a2=5 an envelope can have any integer from 1 to 8 written on it. If the number 7 is written on an envelope, it means that the letter should be delivered to the room number 4 of the second dormitory.
For each of m letters by the room number among all n dormitories, determine the particular dormitory and the room number in a dormitory where this letter should be delivered.
贝兰国立大学共有 n 座宿舍楼,编号为 1 到 n。每座宿舍楼包含若干房间,其中第 i 座宿舍楼有 ai 个房间。第 i 座宿舍楼的房间编号为 1 到 ai。
一名邮递员负责投递信件。有时信封上并未明确写出具体的宿舍楼编号和房间号;取而代之的是,仅写出了所有 n 座宿舍楼全部房间中的一个全局房间编号。此时,我们假定所有房间被统一编号为 1 到 a1+a2+⋯+an,其中第一座宿舍楼的所有房间排在最前,第二座宿舍楼的房间紧随其后,依此类推。
例如,当 n=2、a1=3、a2=5 时,信封上可能出现的编号为 1 到 8 中的任意整数。若信封上写的是数字 7,则表示该信件应投递至第二座宿舍楼的第 4 个房间。
对于 m 封信件,每封信均给出其在全部 n 座宿舍楼中的全局房间编号,请分别确定每封信应投递的具体宿舍楼编号以及该宿舍楼内的房间编号。
输入格式
The first line contains two integers n and m (1≤n,m≤2⋅105) — the number of dormitories and the number of letters.
The second line contains a sequence a1,a2,…,an (1≤ai≤1010), where ai equals to the number of rooms in the i-th dormitory. The third line contains a sequence b1,b2,…,bm (1≤bj≤a1+a2+⋯+an), where bj equals to the room number (among all rooms of all dormitories) for the j-th letter. All bj are given in increasing order.
第一行包含两个整数 n 和 m (1≤n,m≤2⋅105) —— 分别表示宿舍楼的数量和信件的数量。
第二行包含一个序列 a1,a2,…,an (1≤ai≤1010),其中 ai 表示第 i 栋宿舍楼的房间数。
第三行包含一个序列 b1,b2,…,bm (1≤bj≤a1+a2+⋯+an),其中 bj 表示第 j 封信件所对应的房间号(该编号是在所有宿舍楼的所有房间中统一连续编号的)。所有 bj 按升序给出。
输出格式
Print m lines. For each letter print two integers f and k — the dormitory number f (1≤f≤n) and the room number k in this dormitory (1≤k≤af) to deliver the letter.
输出 m 行。对于每封信,输出两个整数 f 和 k —— 分别表示该信件应投递的宿舍楼编号 f(1≤f≤n)以及该宿舍楼内的房间号 k(1≤k≤af)。
输入输出样例
输入#1
3 6 10 15 12 1 9 12 23 26 37
输出#1
1 1 1 9 2 2 2 13 3 1 3 12
输入#2
2 3 5 10000000000 5 6 9999999999
输出#2
1 5 2 1 2 9999999994
说明/提示
In the first example letters should be delivered in the following order:
- the first letter in room 1 of the first dormitory
- the second letter in room 9 of the first dormitory
- the third letter in room 2 of the second dormitory
- the fourth letter in room 13 of the second dormitory
- the fifth letter in room 1 of the third dormitory
- the sixth letter in room 12 of the third dormitory
在第一个例子中,信件应按以下顺序投递:
- 第一封信投递到第一栋宿舍楼的 1 号房间
- 第二封信投递到第一栋宿舍楼的 9 号房间
- 第三封信投递到第二栋宿舍楼的 2 号房间
- 第四封信投递到第二栋宿舍楼的 13 号房间
- 第五封信投递到第三栋宿舍楼的 1 号房间
- 第六封信投递到第三栋宿舍楼的 12 号房间
输入解题思路,AI测评打分。不知道怎么写?