結果

問題 No.143 豆
ユーザー Newbiekun
提出日時 2019-02-20 17:31:07
言語 Java
(openjdk 23)
結果
AC  
実行時間 146 ms / 1,000 ms
コード長 633 bytes
コンパイル時間 3,401 ms
コンパイル使用メモリ 75,520 KB
実行使用メモリ 54,260 KB
最終ジャッジ日時 2024-07-23 11:08:34
合計ジャッジ時間 6,500 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class No143
{
	public static void main(String args[])
	{
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt(); // 1袋に入っている数
		int n = sc.nextInt(); // 袋の数
		int f = sc.nextInt(); // 人数

		int[] age = new int[ f ];
		for( int i=0; i<f; i++ ){ age[ i ] = sc.nextInt(); }

// 総数(k*n)を求めて、配列から要素を1つずつ出して引いていく
		int total = k*n;
		for( int i = (age.length - 1); i >= 0; i-- )
		{ total -= age[ i ]; }

// 豆の合計が -1 以下になったら -1
		if( total <= -1 ){ total = -1; }
		System.out.println( total );
	}
}
0