結果

問題 No.143 豆
ユーザー kazapyon27kazapyon27
提出日時 2017-05-06 14:06:41
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 808 bytes
コンパイル時間 3,852 ms
コンパイル使用メモリ 73,312 KB
実行使用メモリ 60,596 KB
最終ジャッジ日時 2023-10-12 15:04:18
合計ジャッジ時間 7,611 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
55,484 KB
testcase_01 WA -
testcase_02 AC 127 ms
55,540 KB
testcase_03 AC 130 ms
56,068 KB
testcase_04 AC 133 ms
56,064 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 137 ms
55,856 KB
testcase_10 WA -
testcase_11 AC 129 ms
55,916 KB
testcase_12 AC 133 ms
56,336 KB
testcase_13 AC 133 ms
56,224 KB
testcase_14 AC 135 ms
56,172 KB
testcase_15 AC 135 ms
56,028 KB
testcase_16 AC 127 ms
55,912 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/*No.143 豆*/
import java.util.*;
public class No143 {
	public static void main(String[] args) {
		byte family,age_eat=0;
		short tsubu,fukuro;
		int mame;
		try(Scanner input = new Scanner(System.in)){
			tsubu=input.nextShort();
			fukuro=input.nextShort();
			family=input.nextByte();
			byte age[]=new byte[family];
			for(byte i=0;i<age.length;i++){
				age[i]=input.nextByte();
			}
			Arrays.sort(age);
			mame=tsubu*fukuro;
			for(byte j=0;j<age.length;j++){
				if(mame<age[j]){
					mame=0;
					break;
				}else if(mame==age[j]){
					mame=0;
					age_eat++;
					break;
				}else if(mame>age[j]){
					mame-=age[j];
					age_eat++;
				}					
			}
			if(age_eat==0){
				System.out.println(-1);
			}else{
				System.out.println(mame);
			}
		}catch(Exception e){
			e.printStackTrace();
		}
	}
}
0