Created
April 5, 2015 13:58
-
-
Save TPAKC/f8c7d8e80badd0dacf3b to your computer and use it in GitHub Desktop.
This file contains 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.*; | |
import java.io.IOException; | |
public class instrument { | |
public static void main (String[] args) throws IOException | |
{ | |
Scanner in = new Scanner(System.in); | |
int a = in.nextInt(),b = in.nextInt(),summ=0; | |
int[] array= new int[a]; | |
ArrayList<Integer> array2 = new ArrayList<Integer>(); | |
ArrayList<Integer> array3 = new ArrayList<Integer>(); | |
for (int i = 0; i <a; i++) { | |
int n = in.nextInt(); | |
array[i]=n; | |
} | |
int[] array4 = Arrays.copyOf(array,a); | |
Arrays.sort(array); | |
for (int i = 0;summ+array[i]<=b;i++) { | |
summ+=array[i]; | |
array2.add(array[i]); | |
if(i==a-1)break; | |
} | |
for (int i = 0; i <array2.size(); i++) { | |
for (int j = 0; j <array4.length; j++) { | |
if(array2.get(i)==array4[j]) | |
{array3.add(j); | |
array4[j]=-1; | |
break; | |
} | |
} | |
} | |
System.out.println(array2.size()); | |
for(int ch : array3) System.out.print(ch + 1 + " "); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment