chillurbrain

8. Близнецы

May 21st, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. import java.util.Arrays;
  2. import java.util.Scanner;
  3.  
  4. public class Main {
  5. public static void main(String[] args) {
  6. Scanner sc = new Scanner(System.in);
  7. int c = sc.nextInt();
  8. int sum = 0;
  9. int[] values = new int[c];
  10. for (int i = 0; i < c; i++) {
  11. values[i] = sc.nextInt();
  12. sum += values[i];
  13. }
  14. Arrays.sort(values);
  15. int halfSum = 0, coins = 0;;
  16. for (int i = c-1; i >= 0; i--) {
  17. halfSum += values[i];
  18. coins++;
  19. if (halfSum > sum / 2)
  20. break;
  21. }
  22. System.out.println(coins);
  23. }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment