fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone {
  9. public static void main (String[] args) throws java.lang.Exception {
  10. Scanner in = new Scanner(System.in);
  11. int s = in.nextInt();
  12. int n = in.nextInt();
  13. int[] m = new int[n];
  14. for (int i = 0; i < n; i++) m[i] = in.nextInt();
  15. Arrays.sort(m);
  16. LinkedList<Integer> lx = new LinkedList<Integer>();
  17. LinkedList<Integer> ly = new LinkedList<Integer>();
  18. int j = n-1;
  19. for (int i = 0; i < n; i++) {
  20. while (j >= 0 && m[i] + m[j] >= s && m[i] < m[j]) {
  21. if (m[i]+m[j] == s) {
  22. lx.add(m[i]);
  23. ly.add(m[j]);
  24. }
  25. j--;
  26. }
  27. }
  28. for (int i = 0; i < lx.size(); i++){
  29. System.out.println(lx.get(i) + " + " + ly.get(i) + ";");
  30. }
  31. }
  32. }
Success #stdin #stdout 0.1s 380736KB
stdin
4
10
2 2 2 2 2 2 2 2 2 2
stdout
Standard output is empty