Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Main {
- static int N,W;
- static int pow(int n){
- int res = 1;
- for(int i = 0; i < n ; i ++){
- res *= 2;
- }
- return res;
- }
- public static void main(String[] args){
- Scanner sc = new Scanner(System.in);
- N = sc.nextInt();
- int[] a = new int[N];
- int[] c = new int[N];
- W = sc.nextInt();
- for(int i = 0; i < N ; i ++){
- a[i] = sc.nextInt();
- }
- for(int i = 0; i < N; i ++){
- c[i] = sc.nextInt();
- }
- int ans = 0;
- ArrayList<Integer> ansList = new ArrayList<>();
- for(int i = 0; i < pow(N); i ++){
- int cost = 0;
- int weight = 0;
- ArrayList<Integer> list = new ArrayList<>();
- for(int j = 0; j < N; j ++){
- if(((i>>j) & 1) == 1){
- cost += c[j];
- weight += a[j];
- list.add(j+1);
- }
- }
- if(!(weight>W)){
- if(ans < cost){
- ansList = list;
- ans = cost;
- }
- }
- }
- System.out.println(ansList.size());
- for(int i = 0; i < ansList.size(); i++){
- System.out.print(ansList.get(i) + " ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement