Advertisement
erfanul007

LOJ 1048

Dec 8th, 2019
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef unsigned long long int ull;
  5. typedef long long int ll;
  6. typedef vector<int> vi;
  7. typedef vector<ll> vll;
  8. typedef vector<vi> vvi;
  9. typedef pair<int,int > pii;
  10. typedef vector< pii > vpii;
  11. typedef set<int> sti;
  12.  
  13. #define sc scanf
  14. #define pf printf
  15. #define sci(n) scanf("%d",&n)
  16. #define scii(n,m) scanf("%d %d",&n,&m)
  17. #define scl(n) scanf("%lld",&n)
  18. #define scd(n) scanf("%lf",&n)
  19. #define scs(s) scanf("%s",s)
  20. #define pfi(n) printf("%d",n)
  21. #define pfl(n) printf("%lld",n)
  22. #define pff(n) cout<<n
  23. #define line printf("\n")
  24. #define spc printf(" ")
  25. #define clr(a,x) memset(a,x,sizeof(a))
  26. #define loop(i,x,y) for(int i=int(x); i<=int(y); i++)
  27. #define rloop(i,y,x) for(int i=int(y); i>=int(x); i--)
  28. #define cspf(i) printf("Case %d: ", i)
  29. #define vout(v) for(int w=0;w<v.size();w++){if(w) cout<<' '; cout<<v[w];}
  30. #define pb push_back
  31. #define mp make_pair
  32. #define ff first
  33. #define ss second
  34. #define all(v) v.begin(),v.end()
  35. #define rall(v) v.rbegin(),v.rend()
  36. #define read() freopen("input.txt", "r", stdin)
  37. #define write() freopen("output.txt", "w", stdout)
  38. #define fastIO() ios_base::sync_with_stdio(false); cin.tie(NULL);
  39. /// Constants
  40. #define eps 1e-9
  41. #define PI acos(-1.0) // 3.1415926535897932
  42. #define MAX (int)1e9
  43.  
  44. ll GCD(ll a, ll b) { return b == 0 ? a : GCD(b , a % b); }
  45. ll LCM(ll a, ll b) { return a * (b/GCD(a, b)); }
  46.  
  47. int a[1005];
  48. int n,k;
  49.  
  50. bool kth(int val)
  51. {
  52. int kt=1,temp=0;
  53. loop(i,1,n){
  54. temp+=a[i];
  55. if(a[i]>val) return false;
  56. if(temp>val){
  57. kt++;
  58. temp=a[i];
  59. }
  60. }
  61. if(kt>k) return false;
  62. return true;
  63. }
  64.  
  65. int Binary(int lo,int hi)
  66. {
  67. if(lo>hi) return MAX;
  68. int mid = (lo+hi)/2;
  69. //printf("%d\n", mid);
  70. if(kth(mid)) return min(mid,Binary(lo,mid-1));
  71. return Binary(mid+1,hi);
  72. }
  73.  
  74. void Display(int val)
  75. {
  76. int i=1,j=1,temp=0;
  77. printf("%d\n", val);
  78. while(i<=n){
  79. int x = n-i;
  80. int y = k-j;
  81. if(x<y){
  82. if(temp) printf("%d\n", temp);
  83. temp = 0;
  84. loop(b,i,n) printf("%d\n", a[b]);
  85. break;
  86. }
  87. if(temp+a[i]>val){
  88. printf("%d\n", temp);
  89. temp=a[i];
  90. j++;
  91. }
  92. else temp+=a[i];
  93. i++;
  94. }
  95. if(temp) printf("%d\n", temp);
  96. }
  97.  
  98. int main()
  99. {
  100. read();
  101. write();
  102.  
  103. int t;
  104. sci(t);
  105. loop(ca,1,t){
  106. scii(n,k);
  107. n++;
  108. k++;
  109. loop(i,1,n) sci(a[i]);
  110. cspf(ca);
  111. Display(Binary(1,(int)1e8));
  112. }
  113. return 0;
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement