結果

問題 No.143 豆
ユーザー kazapyon27kazapyon27
提出日時 2017-05-06 14:33:30
言語 Java21
(openjdk 21)
結果
AC  
実行時間 134 ms / 1,000 ms
コード長 787 bytes
コンパイル時間 3,297 ms
コンパイル使用メモリ 71,796 KB
実行使用メモリ 56,212 KB
最終ジャッジ日時 2023-09-30 17:02:15
合計ジャッジ時間 6,314 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
55,720 KB
testcase_01 AC 131 ms
55,676 KB
testcase_02 AC 131 ms
55,856 KB
testcase_03 AC 131 ms
55,432 KB
testcase_04 AC 131 ms
55,452 KB
testcase_05 AC 131 ms
55,968 KB
testcase_06 AC 130 ms
55,704 KB
testcase_07 AC 130 ms
55,924 KB
testcase_08 AC 129 ms
55,724 KB
testcase_09 AC 133 ms
56,212 KB
testcase_10 AC 132 ms
56,028 KB
testcase_11 AC 126 ms
55,620 KB
testcase_12 AC 131 ms
55,880 KB
testcase_13 AC 132 ms
55,856 KB
testcase_14 AC 131 ms
55,948 KB
testcase_15 AC 134 ms
55,720 KB
testcase_16 AC 123 ms
55,888 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();
			}
			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!=family){
				System.out.println(-1);
			}else{
				System.out.println(mame);
			}
		}catch(Exception e){
			e.printStackTrace();
		}
	}
}
0