Advertisement
dmkozyrev

c.cpp

May 1st, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #pragma GCC diagnostic ignored "-Wunused-result"
  3.  
  4. typedef int64_t Int;
  5.  
  6. int main() {
  7.     std::ios_base::sync_with_stdio(false);
  8.     std::cin.tie(0); std::cout.tie(0);
  9.    
  10.     int n, q;
  11.     std::cin >> n >> q;
  12.    
  13.     std::vector<Int> a(n); for (auto& it : a) std::cin >> it;
  14.     std::vector<Int> pref{0};
  15.     for (auto it : a) pref.push_back(pref.back()+it);
  16.    
  17.     Int cur = 0;
  18.     for (int i = 0; i < q; ++i) {
  19.         Int k; std::cin >> k;
  20.         cur += k;
  21.         auto it = std::upper_bound(pref.begin(), pref.end(), cur);
  22.         Int answ = Int(pref.end() - it);
  23.         if (answ == 0) {
  24.             cur = 0;
  25.             answ = n;
  26.         }
  27.         std::cout << answ << "\n";
  28.     }
  29.    
  30.    
  31.    
  32.     return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement