結果

問題 No.1619 Coccinellidae
ユーザー merlinmerlin
提出日時 2021-07-22 22:40:53
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,125 bytes
コンパイル時間 3,863 ms
コンパイル使用メモリ 77,352 KB
実行使用メモリ 65,732 KB
最終ジャッジ日時 2023-09-24 18:06:48
合計ジャッジ時間 8,061 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
50,204 KB
testcase_01 WA -
testcase_02 AC 207 ms
58,216 KB
testcase_03 AC 54 ms
50,544 KB
testcase_04 WA -
testcase_05 AC 161 ms
58,148 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 160 ms
59,848 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 187 ms
61,904 KB
testcase_12 AC 55 ms
50,556 KB
testcase_13 WA -
testcase_14 AC 211 ms
61,536 KB
testcase_15 AC 52 ms
50,300 KB
testcase_16 AC 53 ms
50,296 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");
        sb.append(dq.pollLast()+"\n");
        while(!dq.isEmpty()) sb.append(dq.pollFirst()+"\n");
        System.out.print(sb);
    }
}
0