結果
| 問題 |
No.5 数字のブロック
|
| ユーザー |
ajukinkin
|
| 提出日時 | 2016-07-07 16:02:52 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 108 ms / 5,000 ms |
| コード長 | 1,227 bytes |
| コンパイル時間 | 3,977 ms |
| コンパイル使用メモリ | 75,252 KB |
| 実行使用メモリ | 52,756 KB |
| 最終ジャッジ日時 | 2024-11-18 08:44:54 |
| 合計ジャッジ時間 | 6,677 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 34 |
ソースコード
import java.io.*;
import java.util.Arrays;
public class Main01 {
public static void main(String[] args) {
try {
InputStreamReader inputStreamReader = new InputStreamReader(System.in);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
String strBoxLength = bufferedReader.readLine();
int boxLength = Integer.parseInt(strBoxLength);
String strBlockNum = bufferedReader.readLine();
int blockNum = Integer.parseInt(strBlockNum);
String strBoxsWidth = bufferedReader.readLine();
String[] strBoxWidths = strBoxsWidth.split(" ");
int[] boxWidths = new int[strBoxWidths.length];
for (int i = 0; i < blockNum; i++) {
boxWidths[i] = Integer.parseInt(strBoxWidths[i]);
}
// ソート
Arrays.sort(boxWidths);
int width = 0; // 幅
int boxNum = 1; // 箱の個数
for (int i = 0; i < strBoxWidths.length; i++) {
if (width + boxWidths[i] > boxLength) {
break;
}
boxNum = i + 1;
width += boxWidths[i];
}
// 結果出力
System.out.println(boxNum);
} catch (Throwable th) {
th.printStackTrace();
}
}
}
ajukinkin