Codeforces Round #303 Div2 D: Queue (貪欲法)

問題

codeforces.com

コード

import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] people = new int[N];
		for (int i = 0; i < N; i++) {
			people[i] = sc.nextInt();
		}
		Arrays.sort(people);

		long sum = 0;
		int satisfied = 0;
		for (int i = 0; i < people.length; i++) {
			if (sum <= people[i]) {
				satisfied++;
				sum += people[i];
			}
		}
		System.out.println(satisfied);
	}
}