【链接】: CF978C
【分析】:在前缀和数组种二分找到>=询问数的位置,根据位置就好操作了
【代码】:
#include<bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
#define ll long long
#define ms(a,b) memset(a,b,sizeof(a))
#define rep(i,a,b) for(int i=(a); i<=(b); i++)
const int N = 2*1e5+5;
ll a[N],b[N],sum[N];
int main()
{
int n,m;
cin>>n>>m;
memset(sum,0,sizeof(sum));
rep(i,1,n) cin>>a[i], sum[i]=sum[i-1]+a[i];
rep(i,1,m) cin>>b[i];
rep(i,1,m)
{
if(b[i]<=a[1])
printf("%d %lld
",1,b[i]);
else
{
ll j = lower_bound(sum,sum+n,b[i])-sum;
printf("%lld %lld
",j,b[i]-sum[j-1]);
}
}
}