fork download
  1. import java.awt.Point;
  2. import java.io.*;
  3. import java.math.BigInteger;
  4. import java.util.*;
  5. import java.util.Map.Entry;
  6.  
  7. import static java.lang.Math.*;
  8.  
  9. public class Solve implements Runnable{
  10.  
  11. final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;
  12.  
  13.  
  14. void init() throws FileNotFoundException{
  15. if (ONLINE_JUDGE){
  16. //in = new BufferedReader(new InputStreamReader(System.in));
  17. //out = new PrintWriter(System.out);
  18.  
  19. in = new BufferedReader(new FileReader("08"));
  20. out = new PrintWriter("output.txt");
  21. }else{
  22. in = new BufferedReader(new FileReader("08"));
  23. out = new PrintWriter("output.txt");
  24. // in = new BufferedReader(new FileReader("input.txt"));
  25. //out = new PrintWriter("output.txt");
  26. }
  27. }
  28.  
  29. String readString() throws IOException{
  30. while(!tok.hasMoreTokens()){
  31. try{
  32. tok = new StringTokenizer(in.readLine());
  33. }catch (Exception e){
  34. return null;
  35. }
  36. }
  37. return tok.nextToken();
  38. }
  39.  
  40. int readInt() throws IOException{
  41. return Integer.parseInt(readString());
  42. }
  43.  
  44. long readLong() throws IOException{
  45. return Long.parseLong(readString());
  46. }
  47.  
  48. double readDouble() throws IOException{
  49. return Double.parseDouble(readString());
  50. }
  51.  
  52. public static void main(String[] args){
  53. new Thread(null, new Solve(), "", 256 * (1L << 20)).start();
  54. }
  55.  
  56. long timeBegin, timeEnd;
  57.  
  58. void time(){
  59. timeEnd = System.currentTimeMillis();
  60. System.err.println("Time = " + (timeEnd - timeBegin));
  61. }
  62.  
  63. void debug(Object... objects){
  64. if (!ONLINE_JUDGE){
  65. for (Object o: objects){
  66. System.err.println(o.toString());
  67. }
  68. }
  69. }
  70.  
  71. int sm(int x){
  72. if (x==1) return 0;else return 1;
  73. }
  74.  
  75. int gcd(int a,int b){
  76. if (b==0) return a;
  77. else{
  78. return gcd(b,a%b);
  79. }
  80. }
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94. public void solve() throws IOException{
  95. int n=readInt();
  96.  
  97. for (int i=0;i<n;i++){
  98. int k=readInt();
  99. int[] a=new int[k];
  100. for (int j=0;j<k;j++){
  101. a[j]=readInt();
  102. }
  103. Arrays.sort(a);
  104. long k1=0;
  105. for (int j=0;j<k/2;j++){
  106. k1+=(long)a[j];
  107. }
  108. int k2=0;
  109. for (int j=k/2;j<k;j++){
  110. k2+=(long)a[j];
  111. }
  112. out.println(Math.abs(k2-k1));
  113.  
  114. }
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127. }
  128.  
  129.  
  130.  
  131.  
  132.  
  133. public void run(){
  134. try{
  135. timeBegin = System.currentTimeMillis();
  136.  
  137.  
  138. out = new PrintWriter(System.out);
  139.  
  140.  
  141. solve();
  142.  
  143. out.close();
  144. //time();
  145. }catch (Exception e){
  146. e.printStackTrace(System.err);
  147. System.exit(-1);
  148. }
  149. }
  150.  
  151.  
  152. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:9: error: class Solve is public, should be declared in a file named Solve.java
public class Solve implements Runnable{
       ^
1 error
stdout
Standard output is empty