Advertisement
SergeyPGUTI

9.11(черви)

Mar 26th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.00 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <string.h>
  4. #include<cstdlib>
  5. #include<ctime>
  6. #include <vector>
  7. #include <algorithm>
  8. #include <iomanip>
  9.  
  10.  
  11.  
  12. using namespace std;
  13.  
  14.  
  15.  
  16.  
  17.  
  18. int main()
  19. {
  20.     int n,m,buff,wormNumber=0,ID;
  21.     int low,high,mid;
  22.     vector<int> v;
  23.     vector<int> v2;
  24.     cin>>n;
  25.     cin>>buff;
  26.     v.push_back(buff);
  27.     for(int i=1;i<n;i++)
  28.     {
  29.         cin>>buff;
  30.         v.push_back(buff+v[i-1]);
  31.     }
  32.     cin>>m;
  33.     for(int i=0;i<m;i++)
  34.     {
  35.         cin>>buff;
  36.         ID=0;
  37.         low=0;
  38.         high=n-1;
  39.         while(high-low>1)
  40.         {
  41.             mid=low+(high-low)/2;
  42.             if (buff>v[mid]) low=mid;
  43.             else if (buff<v[mid]) high=mid;
  44.             else {
  45.                 ID=mid;
  46.                 break;
  47.             }
  48.         }
  49.         if(ID==mid)
  50.         {
  51.             cout<<mid+1<<endl;
  52.         }
  53.         else
  54.             if(buff<=v[low]) cout<<low+1<<endl;
  55.         else cout<<high+1<<endl;
  56.     }
  57.  
  58.     return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement