2782 Bin Packing

2782 Bin Packing

解答例

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int b = sc.nextInt();
        int[] ls = new int[n];
        for(int i=0;i<n;i++) ls[i] = sc.nextInt();
        
        Arrays.sort(ls);
        
        int inf = 0;
        int sup = n-1;
        int cnt = 0;
        while(true){
            cnt++;
            int x = ls[sup];
            sup--;
            if(inf>sup) break;
            
            int y = ls[inf];
            if(x+y<=b) inf++;
            if(inf>sup) break;
        }
        System.out.println(cnt);
    }
}

タグ:

+ タグ編集
  • タグ:

このサイトはreCAPTCHAによって保護されており、Googleの プライバシーポリシー利用規約 が適用されます。

最終更新:2006年05月14日 00:59
ツールボックス

下から選んでください:

新しいページを作成する
ヘルプ / FAQ もご覧ください。