CF978C.Letters

入门

通过率:0%

时间限制:4.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

There are nn dormitories in Berland State University, they are numbered with integers from 11 to nn. Each dormitory consists of rooms, there are aia_i rooms in ii-th dormitory. The rooms in ii-th dormitory are numbered from 11 to aia_i.

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 nn dormitories is written on an envelope. In this case, assume that all the rooms are numbered from 11 to a1+a2+⋯+ana_1 + a_2 + \dots + a_n 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=2n=2, a1=3a_1=3 and a2=5a_2=5 an envelope can have any integer from 11 to 88 written on it. If the number 77 is written on an envelope, it means that the letter should be delivered to the room number 44 of the second dormitory.

For each of mm letters by the room number among all nn dormitories, determine the particular dormitory and the room number in a dormitory where this letter should be delivered.

贝兰国立大学共有 nn 座宿舍楼,编号为 11 到 nn。每座宿舍楼包含若干房间,其中第 ii 座宿舍楼有 aia_i 个房间。第 ii 座宿舍楼的房间编号为 11 到 aia_i。

一名邮递员负责投递信件。有时信封上并未明确写出具体的宿舍楼编号和房间号;取而代之的是,仅写出了所有 nn 座宿舍楼全部房间中的一个全局房间编号。此时,我们假定所有房间被统一编号为 11 到 a1+a2+⋯+ana_1 + a_2 + \dots + a_n,其中第一座宿舍楼的所有房间排在最前,第二座宿舍楼的房间紧随其后,依此类推。

例如,当 n=2n=2、a1=3a_1=3、a2=5a_2=5 时,信封上可能出现的编号为 11 到 88 中的任意整数。若信封上写的是数字 77,则表示该信件应投递至第二座宿舍楼的第 44 个房间。

对于 mm 封信件,每封信均给出其在全部 nn 座宿舍楼中的全局房间编号,请分别确定每封信应投递的具体宿舍楼编号以及该宿舍楼内的房间编号。

输入格式

The first line contains two integers nn and mm (1≤n,m≤2⋅105)(1 \le n, m \le 2 \cdot 10^{5}) — the number of dormitories and the number of letters.

The second line contains a sequence a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤1010)(1 \le a_i \le 10^{10}), where aia_i equals to the number of rooms in the ii-th dormitory. The third line contains a sequence b1,b2,…,bmb_1, b_2, \dots, b_m (1≤bj≤a1+a2+⋯+an)(1 \le b_j \le a_1 + a_2 + \dots + a_n), where bjb_j equals to the room number (among all rooms of all dormitories) for the jj-th letter. All bjb_j are given in increasing order.

第一行包含两个整数 nn 和 mm (1≤n,m≤2⋅105)(1 \le n, m \le 2 \cdot 10^{5}) —— 分别表示宿舍楼的数量和信件的数量。

第二行包含一个序列 a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤1010)(1 \le a_i \le 10^{10}),其中 aia_i 表示第 ii 栋宿舍楼的房间数。
第三行包含一个序列 b1,b2,…,bmb_1, b_2, \dots, b_m (1≤bj≤a1+a2+⋯+an)(1 \le b_j \le a_1 + a_2 + \dots + a_n),其中 bjb_j 表示第 jj 封信件所对应的房间号(该编号是在所有宿舍楼的所有房间中统一连续编号的)。所有 bjb_j 按升序给出。

输出格式

Print mm lines. For each letter print two integers ff and kk — the dormitory number ff (1≤f≤n)(1 \le f \le n) and the room number kk in this dormitory (1≤k≤af)(1 \le k \le a_f) to deliver the letter.

输出 mm 行。对于每封信,输出两个整数 ff 和 kk —— 分别表示该信件应投递的宿舍楼编号 ff(1≤f≤n1 \le f \le n)以及该宿舍楼内的房间号 kk(1≤k≤af1 \le k \le a_f)。

输入输出样例

  • 输入#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 11 of the first dormitory
  • the second letter in room 99 of the first dormitory
  • the third letter in room 22 of the second dormitory
  • the fourth letter in room 1313 of the second dormitory
  • the fifth letter in room 11 of the third dormitory
  • the sixth letter in room 1212 of the third dormitory

在第一个例子中,信件应按以下顺序投递:

  • 第一封信投递到第一栋宿舍楼的 11 号房间
  • 第二封信投递到第一栋宿舍楼的 99 号房间
  • 第三封信投递到第二栋宿舍楼的 22 号房间
  • 第四封信投递到第二栋宿舍楼的 1313 号房间
  • 第五封信投递到第三栋宿舍楼的 11 号房间
  • 第六封信投递到第三栋宿舍楼的 1212 号房间

输入解题思路,AI测评打分。不知道怎么写?

首页