結果

問題 No.115 遠足のおやつ
ユーザー fal_rnd
提出日時 2017-01-20 22:54:20
言語 Java
(openjdk 23)
結果
AC  
実行時間 128 ms / 5,000 ms
コード長 599 bytes
コンパイル時間 4,402 ms
コンパイル使用メモリ 86,136 KB
実行使用メモリ 41,812 KB
最終ジャッジ日時 2025-01-03 01:21:17
合計ジャッジ時間 9,896 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

package src;

import java.util.*;
public class A{
	static Scanner s = new Scanner(System.in);
	public static void main(String[] args) {
		int sum=0,n=s.nextInt(),d=s.nextInt(),k=s.nextInt();
		int[] r=new int[k];
		for(int i=0;i<k;i++) {
			sum+=i+1;
			r[i]=i+1;
		}
		if(sum>d) {
			System.out.println(-1);
			return;
		}
		for(int i=0;i<k;i++) {
			sum-=r[r.length-1-i];
			r[r.length-1-i]=Math.min(d-sum, n-i);
			sum+=Math.min(d-sum, n-i);
		}
		if(sum==d) {
			System.out.println(Arrays.toString(r).replaceAll("[^0-9,]", "").replaceAll(",", " "));
		}else {
			System.out.println(-1);
		}
	}
}
0