結果

問題 No.664 超能力者Aと株価予測
ユーザー sekiya9311sekiya9311
提出日時 2018-03-09 23:26:16
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 3,346 bytes
コンパイル時間 2,779 ms
コンパイル使用メモリ 79,656 KB
実行使用メモリ 47,332 KB
最終ジャッジ日時 2024-04-19 03:06:52
合計ジャッジ時間 5,911 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 133 ms
41,784 KB
testcase_01 AC 131 ms
41,272 KB
testcase_02 AC 124 ms
41,548 KB
testcase_03 AC 130 ms
41,340 KB
testcase_04 AC 130 ms
41,800 KB
testcase_05 AC 133 ms
41,324 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 130 ms
41,304 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.AbstractCollection;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.Comparator;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        No664 solver = new No664();
        solver.solve(1, in, out);
        out.close();
    }

    static class No664 {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt() + 1;
            int M = in.nextInt();
            long K = in.nextInt();
            int[] A = new int[N];
            for (int i = 0; i < N; i++) {
                A[i] = in.nextInt();
            }
            PriorityQueue<State> pq = new PriorityQueue<>(new Comparator<State>() {

                public int compare(State o1, State o2) {
                    return o2.diff - o1.diff;
                }
            });
            for (int i = 0; i < N; i++) {
                for (int j = i + 1; j < N; j++) {
                    pq.add(new State(i, j, A[j] - A[i]));
                }
            }
            FenwickTree fw = new FenwickTree(N);
            List<State> ans = new ArrayList<>();
            for (int i = 0; i < N && !pq.isEmpty(); i++) {
                State st = pq.poll();
                if (st.diff < 0) break;
                if (fw.get(st.left, st.right + 1) > 0) {
                    i--;
                    continue;
                } else {
                    for (int j = st.left; j <= st.right; j++) {
                        fw.add(j, 1);
                    }
                    ans.add(st);
                }
            }
            ans.sort(new Comparator<State>() {

                public int compare(State o1, State o2) {
                    return o1.left - o2.right;
                }
            });
            for (State st : ans) {
                long foo = K / A[st.left];
                K -= foo * A[st.left];
                K += foo * A[st.right];
            }
            out.println(K);
        }

        public class State {
            public int left;
            public int right;
            public int diff;

            public State(int l, int r, int diff) {
                this.left = l;
                this.right = r;
                this.diff = diff;
            }

        }

    }

    static class FenwickTree {
        private long[] bit;

        public FenwickTree(int n) {
            this.bit = new long[n];
        }

        public void add(int idx, long val) {
            for (int i = idx; i < this.bit.length; i |= i + 1) {
                this.bit[i] += val;
            }
        }

        public long get(int r) {
            long ret = 0;
            for (int i = r - 1; i >= 0; i = (i & (i + 1)) - 1) {
                ret += this.bit[i];
            }
            return ret;
        }

        public long get(int l, int r) {
            return this.get(r) - this.get(l - 1);
        }

    }
}

0