fork(6) download
  1. //ssenseeeeeeeeeeeeeeeeeeeeeeeeeeeee
  2. #include<bits/stdc++.h>
  3. #define startt ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  4. typedef unsigned long long ull;
  5. typedef long long ll;
  6. #define MOD 1000000007
  7. #define MX 1000000000
  8. #define MXL 1000000000000000000
  9. #define PI 3.14159265
  10. #define pb push_back
  11. using namespace std;
  12. #define sc second
  13. #define endl '\n'
  14. #define fr first
  15.  
  16. int main(){
  17. startt
  18. int n,m;
  19. cin >> n >> m;
  20. ll a[n+1];
  21. for(int i = 1;i <=n;i++)
  22. cin >> a[i];
  23. ll prefixSum[n+1];
  24. prefixSum[0] = 0;
  25. prefixSum[1] = a[1];
  26. for(int i = 2;i <= n;i++)
  27. prefixSum[i] = prefixSum[i-1] + a[i];
  28. int b[m+1];
  29. for(int i = 0; i < m; i++)
  30. {
  31. cin >> b[i];
  32. }
  33. for(int i = 0; i< m;i++)
  34. {
  35. int bb = b[i];
  36. int l = 0, r = n;
  37. int ans = n;
  38. while(l<=r)
  39. {
  40. int mid = l + (r - l) / 2;
  41. if(prefixSum[mid] >= bb)
  42. {
  43. ans = mid;
  44. r = mid - 1;
  45. }else{
  46. l = mid + 1;
  47. }
  48. }
  49. if(prefixSum[ans] > bb)
  50. ans--;
  51. cout << ans << " ";
  52. }
  53. }
  54.  
Runtime error #stdin #stdout 0s 4456KB
stdin
Standard input is empty
stdout
Standard output is empty