Advertisement
sherry_ahmos

B-worms

Aug 10th, 2022
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5. #define ll long long
  6. #define nl endl
  7.  
  8. int main()
  9. {
  10.     ll t;
  11.     cin >> t;
  12.     vector<ll> v(t);
  13.     for (int i = 0; i < t; i++)
  14.     {
  15.         cin >> v[i];
  16.         if (i != 0)
  17.             v[i] += v[i - 1] ;
  18.     }
  19.     int ind=0, worms[v[t-1] + 1];
  20.     for (int i = 1; i <= v[t-1]; i++)
  21.     {
  22.         if (i >v[ind])
  23.             ind++;
  24.         worms[i] = ind + 1;
  25.     }
  26.     ll n;
  27.     cin >> n;
  28.     while (n--)
  29.     {
  30.         ll q;
  31.         cin >> q;
  32.         cout<<worms[q]<<nl;
  33.     }
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement