結果

問題 No.143 豆
ユーザー aparachia14aparachia14
提出日時 2015-12-27 00:43:16
言語 Java19
(openjdk 21)
結果
AC  
実行時間 44 ms / 1,000 ms
コード長 1,687 bytes
コンパイル時間 3,568 ms
コンパイル使用メモリ 74,800 KB
実行使用メモリ 49,844 KB
最終ジャッジ日時 2023-09-30 16:40:58
合計ジャッジ時間 4,755 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
49,352 KB
testcase_01 AC 42 ms
49,348 KB
testcase_02 AC 43 ms
49,844 KB
testcase_03 AC 42 ms
49,688 KB
testcase_04 AC 42 ms
49,344 KB
testcase_05 AC 42 ms
49,376 KB
testcase_06 AC 43 ms
47,360 KB
testcase_07 AC 43 ms
49,360 KB
testcase_08 AC 43 ms
49,208 KB
testcase_09 AC 43 ms
49,520 KB
testcase_10 AC 44 ms
49,284 KB
testcase_11 AC 43 ms
49,396 KB
testcase_12 AC 42 ms
49,692 KB
testcase_13 AC 42 ms
49,180 KB
testcase_14 AC 43 ms
49,260 KB
testcase_15 AC 42 ms
47,256 KB
testcase_16 AC 42 ms
49,832 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

//No.143 豆
public class Beans {

	public static void main(String[] args) throws IOException {
		// TODO 自動生成されたメソッド・スタブ
		//入力値を格納する変数
		String input;
		//1袋あたりの豆の数
		int BeansNum = 0;
		//拾った袋の数
		int bagNum = 0;
		//家族の人数
		int familyNum = 0;
		//家族の年齢を格納するArrayList
		ArrayList<Integer> ageList = new ArrayList<Integer>();
		//豆の合計数
		int BeansSum = 0;
		//家族が食べる豆の合計数
		int EatBeanNum = 0;
		
		//入力値の入力待ち
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		input = in.readLine();
		//inputを分割して対応する変数に格納する。
		String[] temp = input.split(" ");
		BeansNum = Integer.parseInt(temp[0]);
		bagNum = Integer.parseInt(temp[1]);
		familyNum = Integer.parseInt(temp[2]);
		
		//入力値の入力待ち
		input = in.readLine();
		//inputを分割して対応する変数に格納する。
		String[] temp2 = input.split(" ");
		for(String temp3:temp2){
			ageList.add(Integer.parseInt(temp3));
		}
		
		//エラー処理
		if(familyNum != ageList.size()){
			System.out.println("入力が間違っています");
			System.exit(1);
		}
		
		//拾った豆の合計数を計算
		BeansSum = BeansNum * bagNum;
		//家族が食べる豆の合計数を計算
		for(int temp4:ageList){
			EatBeanNum += temp4;
		}
		
		if(BeansSum - EatBeanNum < 0){
			System.out.println("-1");
		}else{
			System.out.println(BeansSum - EatBeanNum);
		}
		
		
		

	}

}
0