結果
問題 |
No.247 線形計画問題もどき
|
ユーザー |
![]() |
提出日時 | 2015-07-17 23:27:42 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,244 bytes |
コンパイル時間 | 2,307 ms |
コンパイル使用メモリ | 79,380 KB |
実行使用メモリ | 37,588 KB |
最終ジャッジ日時 | 2024-07-08 09:35:46 |
合計ジャッジ時間 | 4,237 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 14 WA * 9 |
ソースコード
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Collections; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int max = Integer.parseInt(br.readLine()); int nums = Integer.parseInt(br.readLine()); String params[] = br.readLine().split(" "); ArrayList<Integer> list = new ArrayList(); for (int i = 0; i < nums; i++) { list.add(Integer.parseInt(params[i])); } Collections.sort(list); for (int i = list.size() - 1; i >= 0; i--) { int tmpNum = max; int tmpCount = 0; for (int j = i; j >= 0; j--) { while (true) { if (tmpNum >= list.get(j)) { tmpNum = tmpNum - list.get(j); tmpCount++; } else { break; } } } if (tmpNum == 0) { System.out.println(tmpCount); return; } } System.out.println(-1); } }