fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define REP(i,a,b) for(i=a;i<b;i++)
  5. #define rep(i,n) REP(i,0,n)
  6.  
  7. #define mygc(c) (c)=getchar()
  8. #define mypc(c) putchar(c)
  9.  
  10. #define ll long long
  11. #define ull unsigned ll
  12.  
  13. void reader(int *x){int k,m=0;*x=0;for(;;){mygc(k);if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){*x=k-'0';break;}}for(;;){mygc(k);if(k<'0'||k>'9')break;*x=(*x)*10+k-'0';}if(m)(*x)=-(*x);}
  14. void reader(ll *x){int k,m=0;*x=0;for(;;){mygc(k);if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){*x=k-'0';break;}}for(;;){mygc(k);if(k<'0'||k>'9')break;*x=(*x)*10+k-'0';}if(m)(*x)=-(*x);}
  15. void reader(double *x){scanf("%lf",x);}
  16. int reader(char c[]){int i,s=0;for(;;){mygc(i);if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF) break;}c[s++]=i;for(;;){mygc(i);if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF) break;c[s++]=i;}c[s]='\0';return s;}
  17. template <class T, class S> void reader(T *x, S *y){reader(x);reader(y);}
  18. template <class T, class S, class U> void reader(T *x, S *y, U *z){reader(x);reader(y);reader(z);}
  19. template <class T, class S, class U, class V> void reader(T *x, S *y, U *z, V *w){reader(x);reader(y);reader(z);reader(w);}
  20.  
  21. void writer(int x, char c){int s=0,m=0;char f[10];if(x<0)m=1,x=-x;while(x)f[s++]=x%10,x/=10;if(!s)f[s++]=0;if(m)mypc('-');while(s--)mypc(f[s]+'0');mypc(c);}
  22. void writer(ll x, char c){int s=0,m=0;char f[20];if(x<0)m=1,x=-x;while(x)f[s++]=x%10,x/=10;if(!s)f[s++]=0;if(m)mypc('-');while(s--)mypc(f[s]+'0');mypc(c);}
  23. void writer(double x, char c){printf("%.15f",x);mypc(c);}
  24. void writer(const char c[]){int i;for(i=0;c[i]!='\0';i++)mypc(c[i]);}
  25. void writer(const char x[], char c){int i;for(i=0;x[i]!='\0';i++)mypc(x[i]);mypc(c);}
  26. template<class T> void writerLn(T x){writer(x,'\n');}
  27. template<class T, class S> void writerLn(T x, S y){writer(x,' ');writer(y,'\n');}
  28. template<class T, class S, class U> void writerLn(T x, S y, U z){writer(x,' ');writer(y,' ');writer(z,'\n');}
  29. template<class T> void writerArr(T x[], int n){int i;if(!n){mypc('\n');return;}rep(i,n-1)writer(x[i],' ');writer(x[n-1],'\n');}
  30.  
  31. char memarr[17000000]; void *mem = memarr;
  32. #define MD 1000000007
  33.  
  34. int N, Q;
  35. int A[3100000];
  36. ll K;
  37.  
  38. int arr[3100000];
  39.  
  40. int main(){
  41. int i, j, k;
  42. ll tot; int cnt;
  43. int res;
  44.  
  45. reader(&N,&Q);
  46. rep(i,N) reader(A+i);
  47. rep(i,N) A[i+N] = A[i];
  48. rep(i,N) A[i+N+N] = A[i];
  49.  
  50. while(Q--){
  51. reader(&K);
  52.  
  53. cnt = 0;
  54. tot = 0;
  55. rep(i,3*N){
  56. if(tot + A[i] > K){ tot = 0; cnt++; }
  57. tot += A[i];
  58. arr[i] = cnt;
  59. }
  60. res = 3 * N;
  61. REP(i,N,3*N) res = min(res, arr[i] - arr[i-N+1] + 1);
  62.  
  63. writerLn(res);
  64. }
  65.  
  66. return 0;
  67. }
Success #stdin #stdout 0s 43928KB
stdin
12 1
10 13 14 8 15 11 8 1 7 14 10 11
61
stdout
3