fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. #define int long long
  5. #define yes cout << "YES\n";
  6. #define no cout << "NO\n";
  7.  
  8.  
  9. void FastIO() {
  10. ios_base::sync_with_stdio(false);
  11. cin.tie(nullptr);
  12. cout.tie(nullptr);
  13. }
  14.  
  15. void solve(){
  16. int n;
  17. cin >> n;
  18. vector<int>v(n);
  19.  
  20. for(int i = 0; i < n; i++){
  21. cin >> v[i];
  22.  
  23. if(i)
  24. v[i] += v[i-1];
  25. }
  26.  
  27. int m;
  28. cin >> m;
  29.  
  30. while(m--){
  31. int x;
  32. cin >> x;
  33.  
  34. int l = 0, r = n-1, ans = -1, mid;
  35.  
  36. while(l<=r){
  37. mid = l + (r-l)/2;
  38.  
  39. if(v[mid] >= x){
  40. ans = mid;
  41. r = mid - 1;
  42. }
  43. else
  44. l = mid+1 ;
  45. }
  46. if(ans == -1) cout << n << '\n';
  47. else cout << ans+1 << '\n';
  48. }
  49. }
  50.  
  51.  
  52. signed main(){
  53. FastIO();
  54.  
  55. int t = 1;
  56. //cin >> t;
  57.  
  58. while (t--){
  59. solve();
  60. }
  61. return 0;
  62. }
Success #stdin #stdout 0.01s 5316KB
stdin
5
2 7 3 4 9
3
1 25 11
stdout
1
5
3