fork download
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. //freopen("input.txt","r",stdin);
  9. ll n,m,q;
  10. cin >> n >> m >> q;
  11. ll a[m];
  12. for(int i=0;i<m;i++) cin >> a[i];
  13. for(int i=m-2;i>=0;i--) a[i]=a[i]+a[i+1];
  14. while(q--)
  15. {
  16. ll x; cin >> x;
  17. ll low=0,high=m-1,pos=-1;
  18. while(low<=high)
  19. {
  20. ll mid = (low+high)/2;
  21. if(a[mid]>x)
  22. {
  23. low=mid+1;
  24. }
  25. else if(a[mid]<x)
  26. {
  27. high=mid-1;
  28. }
  29. else
  30. {
  31. pos=mid;
  32. break;
  33. }
  34. }
  35. if(pos==-1) cout << high+1 << endl;
  36. else cout << pos+1 << endl;
  37. }
  38. return 0;
  39. }
  40.  
Success #stdin #stdout 0s 5324KB
stdin
25 5 3
9 4 3 7 2
1 25 11
stdout
5
1
3