結果

問題 No.1619 Coccinellidae
ユーザー merlinmerlin
提出日時 2021-07-22 22:45:26
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,144 bytes
コンパイル時間 4,205 ms
コンパイル使用メモリ 76,812 KB
実行使用メモリ 63,644 KB
最終ジャッジ日時 2023-09-24 18:19:51
合計ジャッジ時間 9,289 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
49,972 KB
testcase_01 WA -
testcase_02 AC 206 ms
61,976 KB
testcase_03 AC 52 ms
50,016 KB
testcase_04 WA -
testcase_05 AC 160 ms
57,908 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 163 ms
60,112 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 180 ms
61,784 KB
testcase_12 AC 54 ms
50,168 KB
testcase_13 WA -
testcase_14 AC 213 ms
61,720 KB
testcase_15 AC 52 ms
49,960 KB
testcase_16 AC 52 ms
50,388 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

class Main
{
    public static void main(String args[])throws Exception
    {
        BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb=new StringBuilder();
        String s[]=bu.readLine().split(" ");
        int n=Integer.parseInt(s[0]),i;
        long m=Long.parseLong(s[1]),k=Long.parseLong(s[2]),sum=0;
        Deque<Long> dq=new LinkedList<>();
        for(i=0;i<n;i++)
        {
            dq.addLast((long)i+1);
            sum+=i+1;
        }
        long v=dq.pollLast();
        v+=m-sum;
        dq.addLast(v);

        int cur=n-1;
        Queue<Long> q=new LinkedList<>();
        while(cur>=0 && k-cur>=0)    //one by one take largest and place it after the last appended value
        {
            q.add(dq.pollLast());
            k-=cur;
            cur--;
        }

        while(!q.isEmpty()) sb.append(q.poll()+"\n");
        while(dq.size()>k+1) sb.append(dq.pollFirst()+"\n");
        if(!dq.isEmpty()) sb.append(dq.pollLast()+"\n");
        while(!dq.isEmpty()) sb.append(dq.pollFirst()+"\n");
        System.out.print(sb);
    }
}
0