fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. // your code goes here
  6. int t;
  7. cin>>t;
  8. while(t--)
  9. {
  10. int n,k;
  11. cin>>n>>k;
  12. int a[n],s=0;
  13. for(int i=0;i<n;i++)
  14. {
  15. cin>>a[i];
  16. s=s+a[i];
  17. }
  18. int x=s/k;
  19. int c=a[0],i;
  20. cout<<a[0]<<" ";
  21. s=0;
  22. for(i=1;i<n;i++)
  23. {
  24. c=c+a[i];
  25. if(c>x)
  26. {
  27. cout<<" / "<<a[i]<<" ";
  28. c=a[i];
  29. s++;
  30. }
  31. else
  32. {
  33. cout<<a[i]<<" ";
  34. }
  35. if(s==k-1)
  36. break;
  37. }
  38. i=i+1;
  39. while(i<n)
  40. cout<<a[i++]<<" ";
  41. cout<<endl;
  42. }
  43. return 0;
  44. }
Success #stdin #stdout 0.01s 5520KB
stdin
2
9 3
100 200 300 400 500 600 700 800 900
5 4
100 100 100 100 100
stdout
100 200 300 400 500  / 600 700  / 800 900 
100  / 100  / 100  / 100 100