fork(3) download
  1. import java.io.*;
  2. import java.util.*;
  3. import java.awt.*;
  4. import java.math.*;
  5.  
  6. public class Main implements Runnable {
  7.  
  8. static PrintWriter out = new PrintWriter( new BufferedOutputStream(System.out) );
  9. public static void main(String [] asda) throws Exception {
  10. new Thread(null, new Main(), "Main", 1 << 28).start();
  11. }
  12.  
  13. public void run() {
  14. InputReader reader = new InputReader(System.in);
  15.  
  16. int CASES = reader.readInt();
  17. while (CASES-- > 0) {
  18. int N = reader.readInt();
  19. int M = reader.readInt();
  20. int [] v = new int [N];
  21. for (int k = 0; k < N; k++) v[k] = reader.readInt();
  22.  
  23. solve(N, M, v);
  24. }
  25.  
  26. //
  27. out.close();
  28. System.exit(0);
  29. }
  30. void solve(int N, int M, int [] v) {
  31. long lo = 0, hi = 0;
  32. for (int k = 0; k < N; k++) {
  33. lo = Math.max(lo, v[k]);
  34. hi += v[k];
  35. }
  36.  
  37. long ans = hi;
  38. long sum = 0;
  39. while ( lo <= hi ) {
  40. long mid = (lo + hi) >> 1;
  41. int req = 1;
  42. sum = 0;
  43. for (int k = 0; k < N; k++) {
  44. if ( sum + v[k] <= mid ) sum += v[k];
  45. else {
  46. sum = v[k];
  47. req++;
  48. }
  49. }
  50.  
  51. if ( req <= M ) {
  52. ans = mid;
  53. hi = mid - 1;
  54. } else lo = mid + 1;
  55. }
  56.  
  57. // ans is max value
  58. StringBuilder sb = new StringBuilder();
  59. sb.append( v[N - 1] );
  60. sum = v[N - 1];
  61. M--;
  62. for (int k = N - 2; k >= 0; k--) {
  63. if ( sum + v[k] <= ans && k + 1 > M ) {
  64. sb.insert(0, " ");
  65. sum += v[k];
  66. } else {
  67. sum = v[k];
  68. sb.insert(0, " / ");
  69. M--;
  70. }
  71. sb.insert(0, v[k]);
  72. }
  73. out.println(sb);
  74. }
  75. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:14: error: cannot find symbol
		InputReader reader = new InputReader(System.in);
		^
  symbol:   class InputReader
  location: class Main
Main.java:14: error: cannot find symbol
		InputReader reader = new InputReader(System.in);
		                         ^
  symbol:   class InputReader
  location: class Main
2 errors
stdout
Standard output is empty