Codeforces Round #481 (Div. 3) C. Letters
C. Letters
Example 1 input 3 6 10 15 12 1 9 12 23 26 37 output 1 1 1 9 2 2 2 13 3 1 3 12 Example 2 input 2 3 5 10000000000 5 6 9999999999 output 1 5 2 1 2 9999999994
题目大意:
题目大意: 假设宿舍a,b,c分别有1,2,3间房间,如果有一份邮件上写着3说明就是b宿舍的第二间房间的信,而题目就是给你一个信封上的数字, 让你输出寝室号和房间号
分析:
分析: 先对有所房间数做前缀和,用lower_bound去搜信封上的数字,lower_bound出来的位子就是这个寝室号,房间号也就很轻松的算出来了。
code:
#define debug #include<bits/stdc++.h> #define pb push_back #define dbg(x) cout<<#x<<" = "<<(x)<<endl; #define lson l,m,rt<<1 #define cmm(x) cout<<"("<<(x)<<")"; #define rson m+1,r,rt<<1|1 using namespace std; typedef long long ll; typedef pair<int,int> pii; typedef pair<ll,ll>PLL; typedef pair<int,ll>Pil; const ll INF = 0x3f3f3f3f; const ll inf=0x7fffffff; const double eps=1e-8; const int maxn =1e6+10; const int N = 510; const ll mod=1e9+7; const ll MOD=1e9; //------ //define ll a[maxn]; ll ev[maxn]; ll sum[maxn]; //solve void solve() { int n,m; while(cin>>n>>m) { for(int i=1;i<=n;i++){ cin>>a[i]; sum[i]=sum[i-1]+a[i]; // cout<<sum[i]<<" "; } //cout<<endl; for(int i=1;i<=m;i++){ cin>>ev[i]; } for(int i=1;i<=m;i++){ int p=lower_bound(sum+1,sum+1+n,ev[i])-sum+1-1; cout<<p<<" "<<a[p]-sum[p]+ev[i]<<endl; } } } int main() { ios_base::sync_with_stdio(false); #ifdef debug freopen("in.txt", "r", stdin); // freopen("out.txt","w",stdout); #endif cin.tie(0); cout.tie(0); solve(); /* #ifdef debug fclose(stdin); fclose(stdout); system("out.txt"); #endif */ return 0; }