Created
July 17, 2016 13:43
-
-
Save Jack-Saleem/5bb87f9be13f16c26d1d043acfb39938 to your computer and use it in GitHub Desktop.
codeforces 160A Twins program in java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Arrays; | |
import java.util.Scanner; | |
public class Twins | |
{ | |
public static void main(String[] args) | |
{ | |
Scanner z=new Scanner(System.in); | |
int n=z.nextInt(); | |
int []a=new int[n]; | |
int tot=0; | |
for(int i=0;i<n;i++){ | |
a[i]=z.nextInt(); | |
tot+=a[i]; | |
} | |
tot=tot/2; | |
Arrays.sort(a); | |
int k=0,k1=0; | |
for(int i=n-1;i>0;i--) | |
{ | |
k1+=a[i]; | |
if(k1>tot) | |
break; | |
else | |
k++; | |
} | |
System.out.println(k+1); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Twins Problem Solution