結果
| 問題 | 
                            No.115 遠足のおやつ
                             | 
                    
| コンテスト | |
| ユーザー | 
                             holeguma
                         | 
                    
| 提出日時 | 2015-08-22 00:16:17 | 
| 言語 | Java  (openjdk 23)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 971 bytes | 
| コンパイル時間 | 2,349 ms | 
| コンパイル使用メモリ | 84,128 KB | 
| 実行使用メモリ | 52,952 KB | 
| 最終ジャッジ日時 | 2024-07-18 12:27:00 | 
| 合計ジャッジ時間 | 5,797 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 WA * 2 | 
| other | AC * 15 WA * 25 | 
ソースコード
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 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(d-sum);
}
else out.println(-1);
}
out.flush();
}
}
            
            
            
        
            
holeguma