Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <string.h>
- #include<cstdlib>
- #include<ctime>
- #include <vector>
- #include <algorithm>
- #include <iomanip>
- using namespace std;
- int main()
- {
- int n,m,buff,wormNumber=0,ID;
- int low,high,mid;
- vector<int> v;
- vector<int> v2;
- cin>>n;
- cin>>buff;
- v.push_back(buff);
- for(int i=1;i<n;i++)
- {
- cin>>buff;
- v.push_back(buff+v[i-1]);
- }
- cin>>m;
- for(int i=0;i<m;i++)
- {
- cin>>buff;
- ID=0;
- low=0;
- high=n-1;
- while(high-low>1)
- {
- mid=low+(high-low)/2;
- if (buff>v[mid]) low=mid;
- else if (buff<v[mid]) high=mid;
- else {
- ID=mid;
- break;
- }
- }
- if(ID==mid)
- {
- cout<<mid+1<<endl;
- }
- else
- if(buff<=v[low]) cout<<low+1<<endl;
- else cout<<high+1<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement