fork download
  1. //Task: popcorn
  2. //Author: Kinka Kirilova-Lupanova
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. int n,k,s,a,b,c,i;
  7. int p[100001];
  8. bool can_eat(int t) // modelirane
  9. { int i,j,e;
  10. j=1;
  11. for (i=1; i<=k; i++)
  12. {e=0;
  13. while (j<=n && (e+p[j]+s-1)/s<=t)
  14. {e=e+p[j];
  15. j++;
  16. }
  17. }
  18. return (j>n);
  19. }
  20. int main()
  21. {cin>>n>>k>>s;
  22. for (i=1; i<=n; i++) cin>>p[i];
  23. a=1;
  24. b=1000000001;
  25. while (a<b) // dvoi4no tyrsene
  26. {c=(b+a)/2;
  27. if (can_eat(c)) b=c;
  28. else a=c+1;
  29. }
  30. cout<<a<<endl;
  31. return 0;
  32. }
  33.  
Success #stdin #stdout 0s 5320KB
stdin
5 3 3
5 6 1 10 7
stdout
4