結果
| 問題 |
No.115 遠足のおやつ
|
| コンテスト | |
| ユーザー |
holeguma
|
| 提出日時 | 2015-08-22 00:18:04 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 80 ms / 5,000 ms |
| コード長 | 982 bytes |
| コンパイル時間 | 2,305 ms |
| コンパイル使用メモリ | 81,752 KB |
| 実行使用メモリ | 52,228 KB |
| 最終ジャッジ日時 | 2025-01-03 01:06:54 |
| 合計ジャッジ時間 | 6,473 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 40 |
ソースコード
import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;
public class Main{
static final InputStream in=System.in;
static final PrintWriter out=new PrintWriter(System.out);
public static boolean check(int now,int n,int d,int k){
if((2*now+k-1)*k/2>d||(2*n-k+1)*k/2<d) return false;
return true;
}
public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(in));
StringTokenizer st;
String line="";
while((line=br.readLine())!=null&&!line.isEmpty()){
st=new StringTokenizer(line);
int n=Integer.parseInt(st.nextToken());
int d=Integer.parseInt(st.nextToken());
int k=Integer.parseInt(st.nextToken());
int cd=d;
int sum=0;
int[] ans=new int[k+1];
if(check(1,n,d,k)){
lo: for(int i=1;i<k;i++){
for(int j=ans[i-1]+1;j<=n;j++){
if(check(j+1,n,d-j,k-i)){
d-=j;
ans[i]=j;
sum+=j;
continue lo;
}
}
}
for(int i=1;i<k;i++) out.print(ans[i]+" ");
out.println(cd-sum);
}
else out.println(-1);
}
out.flush();
}
}
holeguma