fork download
  1. #include <bits/stdc++.h>
  2. #define VuDucNam ios_base::sync_with_stdio(false);
  3. #define Lop9a6 cin.tie(NULL);
  4. #define THCSPhamVanDong cout.tie(NULL);
  5. #define ll long long
  6. #define el cout << '\n'
  7. #define sz(a) (ll) a.size()
  8. #define all(a) a.begin(), a.end()
  9. #define fi first
  10. #define se second
  11. #define fill(a, x) memset(a, x, sizeof(a))
  12. #define file(name) \
  13.   if (fopen(name ".inp", "r")) \
  14.   { \
  15.   freopen(name ".inp", "r", stdin); \
  16.   freopen(name ".out", "w", stdout); \
  17.   }
  18. #define TIME (1.0 * clock() / CLOCKS_PER_SEC)
  19. #define RUNTIME cerr << "\nRuntime: " << TIME << "s.\n"
  20.  
  21. using namespace std;
  22.  
  23. const int N5 = 1e5 + 5;
  24. const ll MOD = 1e9 + 7;
  25. const ll inf = LLONG_MAX;
  26.  
  27. int n,m;
  28. ll pre[N5];
  29.  
  30. void solve()
  31. {
  32. cin >> n;
  33. for(int i=1;i<=n;++i){
  34. ll x;
  35. cin >> x;
  36. pre[i]=pre[i-1]+x;
  37. }
  38. cin >> m;
  39. for(int i=1;i<=m;++i){
  40. ll x;
  41. cin >> x;
  42. int ans=lower_bound(pre+1,pre+n+1,x)-pre;
  43. if(ans==n+1)
  44. cout << -1 << " ";
  45. else
  46. cout << ans << " ";
  47. }
  48. el;
  49. }
  50.  
  51. int main()
  52. {
  53. VuDucNam Lop9a6 THCSPhamVanDong
  54. // file();
  55. solve();
  56. RUNTIME;
  57. return 0;
  58. }
  59.  
Success #stdin #stdout #stderr 0.01s 5288KB
stdin
5
5 4 1 2 3
4
5 6 12 100
stdout
1 2 4 -1 
stderr
Runtime: 0.005087s.