Http://codeforces.com/problemset/problem/545/D
Test instructions: N Number of Service request arrays, for the maximum number of requests to satisfy the service during its service time
First, the service request array is sorted from small to large.
The relationship between the service time t and sum of the preceding service time is judged below
If T sum: number of waiting services +1
If T>sum: The description can be serviced within the service waiting time t. Time that has been served sum+ the time t to change the request is the new time that has been served and
Note: Sum is the service time that satisfies the condition and
Java Program:
Importjava.util.Arrays;ImportJava.util.Scanner; Public classD545 {/** * @paramargs*/ Static voidrun () {Scanner SC=NewScanner (system.in); intn =Sc.nextint (); int[] t =New int[n]; intsum = 0; intCount = 0; for(inti=0;i<n;i++) {T[i]=Sc.nextint (); } arrays.sort (t); for(inti=0;i<n;i++){ if(sum>T[i]) Count++; Elsesum+=T[i];//System.out.print (sum+ "");} System.out.println (n-count); } Public Static voidMain (string[] args) {//TODO auto-generated Method Stubrun (); }}View Code
Python program:
n = raw_input () t = map (Int,raw_input (). Split ()) count = 0sum = 0for ti in sorted (t): if sum<= ti: count + = 1
sum + = Tiprint count
545D. Queue