博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
codeforces 978C Letters
阅读量:4364 次
发布时间:2019-06-07

本文共 3459 字,大约阅读时间需要 11 分钟。

C. Letters
time limit per test
4 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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

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++ana1+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=2n=2, a1=3a1=3 and a2=5a2=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.

Input

The first line contains two integers nn and m(1n,m2105)(1≤n,m≤2⋅105) — the number of dormitories and the number of letters.

The second line contains a sequence a1,a2,,ana1,a2,…,an (1ai1010)(1≤ai≤1010), where aiai equals to the number of rooms in the ii-th dormitory. The third line contains a sequence b1,b2,,bmb1,b2,…,bm (1bja1+a2++an)(1≤bj≤a1+a2+⋯+an), where bjbj equals to the room number (among all rooms of all dormitories) for the jj-th letter. All bjbj are given in increasing order.

Output

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

Examples
input
Copy
3 6 10 15 12 1 9 12 23 26 37
output
Copy
1 1 1 9 2 2 2 13 3 1 3 12
input
Copy
2 3 5 10000000000 5 6 9999999999
output
Copy
1 5 2 1 2 9999999994
Note

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

题意:n个宿舍,每个宿舍有ai个房间,再给你m个数,问每个数在第几个宿舍的第几个房间。

分析:很简单的模拟,但是数据量很大,a数组里面每个数都要是long long,而且如果直接遍历求解的话会T掉,我第一个想到的就是学长在寒假教过的二分查找,很长时间没写二分有点忘。。。改了几次才过了样例,然后交上去就过了

1 #include 
2 using namespace std; 3 #define fi first 4 #define se second 5 #define ll long long 6 #define pb push_back 7 const int N=2e5+5; 8 ll a[N]; 9 ll b[N];10 int main()11 {12 int n,m;13 scanf("%d %d",&n,&m);14 for (int i=1;i<=n;i++)15 {16 scanf("%I64d",&a[i]);17 b[1]=a[1];18 b[i]=b[i-1]+a[i];19 }20 int flag1,flag2;21 while(m--)22 {23 int flag;24 ll t;25 scanf("%I64d",&t);26 ll l=0,r=n;27 while(l+1
t) flag=1;31 if(b[mid]<=t) flag=2;32 if(flag==1) r=mid;33 else if(flag==2) l=mid;34 }35 if(t-b[l]==0)36 printf("%I64d %I64d\n",l,a[l]);37 else printf("%I64d %I64d\n",l+1,t-b[l]);38 }39 }

 

转载于:https://www.cnblogs.com/TheSilverMoon/p/9129599.html

你可能感兴趣的文章
english interview
查看>>
寒假222_codeforces 290 div 2 D
查看>>
open-falcon(v0.2)部署手册(源码编译)
查看>>
大明A+B(hdu1753)大数,java
查看>>
局部变量&&malloc函数&&生命周期的一些见解
查看>>
springboot打jar包,调用webservice出错
查看>>
一审七个月了
查看>>
xth的旅行(codevs 1450)
查看>>
sql 表有没有自增列,插入自增列值
查看>>
php ajax请求判断
查看>>
sqlserver 行列旋转
查看>>
Winform圆角窗体绘制
查看>>
【题解】移动牛棚
查看>>
注解与配置的配合使用
查看>>
查询某个字段属于哪些表
查看>>
IOS 使用NSKeyedArchiver类进行对象序列化和反序列化
查看>>
finereport报表--动态格间运算 二
查看>>
apache2.2 虚拟主机配置(转)
查看>>
POJ 2386 Lake Counting
查看>>
关于注册模型失败的分析
查看>>