답안 #523638

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
523638 2022-02-08T02:32:51 Z Longgggggggg Cloud Computing (CEOI18_clo) Java 11
100 / 100
2939 ms 15184 KB
import java.io.*;
import java.util.Arrays;
import java.util.Comparator;
import java.util.InputMismatchException;

public class clo {
    static long INF = (long) 1e18;

    public static void main(String[] args) {
        FastIO io = new FastIO();
        int n = io.nextInt();
        Item[] items = new Item[n];
        for (int i = 0; i < n; i++) items[i] = new Item(io.nextInt(), io.nextInt(), -io.nextInt());
        int m = io.nextInt();
        items = Arrays.copyOf(items, m + n);
        for (int i = 0; i < m; i++) items[n + i] = new Item(-io.nextInt(), io.nextInt(), io.nextInt());
        Arrays.sort(items, (a, b) -> a.f == b.f ? a.p - b.p : b.f - a.f);
        long[][] dp = new long[2][50 * n + 1];
        for (long[] row : dp) Arrays.fill(row, -INF);
        dp[0][0] = 0;
        for (int i = 1; i <= n + m; i++) {
            for (int j = 0; j <= 50 * n; j++) {
                dp[i % 2][j] = dp[(i - 1) % 2][j];
                if (j >= items[i - 1].c && j - items[i - 1].c <= 50 * n)
                    dp[i % 2][j] = Math.max(dp[(i - 1) % 2][j - items[i - 1].c] + items[i - 1].p, dp[i % 2][j]);
            }
        }
        long max = 0;
        for (int j = 0; j <= 50 * n; j++) max = Math.max(dp[(m + n) % 2][j], max);
        io.println(max);
        io.close();
    }

    static class Item {
        int c, f, p;

        public Item(int c, int f, int p) {
            this.c = c;
            this.f = f;
            this.p = p;
        }
    }

    private static class FastIO extends PrintWriter {
        private final InputStream stream;
        private final byte[] buf = new byte[1 << 16];
        private int curChar, numChars;

        // standard input
        public FastIO() {
            this(System.in, System.out);
        }

        public FastIO(InputStream i, OutputStream o) {
            super(o);
            stream = i;
        }

        // file input
        public FastIO(String i, String o) throws IOException {
            super(new FileWriter(o));
            stream = new FileInputStream(i);
        }

        // throws InputMismatchException() if previously detected end of file
        private int nextByte() {
            if (numChars == -1) throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars == -1) return -1; // end of file
            }
            return buf[curChar++];
        }

        // to read in entire lines, replace c <= ' '
        // with a function that checks whether c is a line break
        public String next() {
            int c;
            do {
                c = nextByte();
            } while (c <= ' ');
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = nextByte();
            } while (c > ' ');
            return res.toString();
        }

        public int nextInt() { // nextLong() would be implemented similarly
            int c;
            do {
                c = nextByte();
            } while (c <= ' ');
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = nextByte();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') throw new InputMismatchException();
                res = 10 * res + c - '0';
                c = nextByte();
            } while (c > ' ');
            return res * sgn;
        }

        public long nextLong() { // nextLong() would be implemented similarly
            int c;
            do {
                c = nextByte();
            } while (c <= ' ');
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = nextByte();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') throw new InputMismatchException();
                res = 10 * res + c - '0';
                c = nextByte();
            } while (c > ' ');
            return res * sgn;
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }
    }

}
# 결과 실행 시간 메모리 Grader output
1 Correct 75 ms 8676 KB Output is correct
2 Correct 73 ms 8936 KB Output is correct
3 Correct 84 ms 10612 KB Output is correct
4 Correct 84 ms 10292 KB Output is correct
5 Correct 112 ms 10668 KB Output is correct
6 Correct 112 ms 10552 KB Output is correct
7 Correct 130 ms 10540 KB Output is correct
8 Correct 116 ms 10432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 66 ms 9176 KB Output is correct
2 Correct 67 ms 8764 KB Output is correct
3 Correct 96 ms 10484 KB Output is correct
4 Correct 99 ms 10520 KB Output is correct
5 Correct 411 ms 12272 KB Output is correct
6 Correct 381 ms 12368 KB Output is correct
7 Correct 1395 ms 14260 KB Output is correct
8 Correct 1372 ms 14208 KB Output is correct
9 Correct 1330 ms 14096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 84 ms 10368 KB Output is correct
2 Correct 82 ms 10452 KB Output is correct
3 Correct 104 ms 10616 KB Output is correct
4 Correct 99 ms 10416 KB Output is correct
5 Correct 127 ms 10716 KB Output is correct
6 Correct 133 ms 10596 KB Output is correct
7 Correct 134 ms 10292 KB Output is correct
8 Correct 141 ms 10728 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 66 ms 8948 KB Output is correct
2 Correct 66 ms 8872 KB Output is correct
3 Correct 851 ms 12828 KB Output is correct
4 Correct 114 ms 10480 KB Output is correct
5 Correct 2527 ms 14824 KB Output is correct
6 Correct 2628 ms 13944 KB Output is correct
7 Correct 2603 ms 14108 KB Output is correct
8 Correct 2635 ms 14092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 66 ms 8956 KB Output is correct
2 Correct 97 ms 10632 KB Output is correct
3 Correct 279 ms 11904 KB Output is correct
4 Correct 662 ms 12324 KB Output is correct
5 Correct 2904 ms 15184 KB Output is correct
6 Correct 2825 ms 13936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 75 ms 8676 KB Output is correct
2 Correct 73 ms 8936 KB Output is correct
3 Correct 84 ms 10612 KB Output is correct
4 Correct 84 ms 10292 KB Output is correct
5 Correct 112 ms 10668 KB Output is correct
6 Correct 112 ms 10552 KB Output is correct
7 Correct 130 ms 10540 KB Output is correct
8 Correct 116 ms 10432 KB Output is correct
9 Correct 66 ms 9176 KB Output is correct
10 Correct 67 ms 8764 KB Output is correct
11 Correct 96 ms 10484 KB Output is correct
12 Correct 99 ms 10520 KB Output is correct
13 Correct 411 ms 12272 KB Output is correct
14 Correct 381 ms 12368 KB Output is correct
15 Correct 1395 ms 14260 KB Output is correct
16 Correct 1372 ms 14208 KB Output is correct
17 Correct 1330 ms 14096 KB Output is correct
18 Correct 84 ms 10368 KB Output is correct
19 Correct 82 ms 10452 KB Output is correct
20 Correct 104 ms 10616 KB Output is correct
21 Correct 99 ms 10416 KB Output is correct
22 Correct 127 ms 10716 KB Output is correct
23 Correct 133 ms 10596 KB Output is correct
24 Correct 134 ms 10292 KB Output is correct
25 Correct 141 ms 10728 KB Output is correct
26 Correct 66 ms 8948 KB Output is correct
27 Correct 66 ms 8872 KB Output is correct
28 Correct 851 ms 12828 KB Output is correct
29 Correct 114 ms 10480 KB Output is correct
30 Correct 2527 ms 14824 KB Output is correct
31 Correct 2628 ms 13944 KB Output is correct
32 Correct 2603 ms 14108 KB Output is correct
33 Correct 2635 ms 14092 KB Output is correct
34 Correct 66 ms 8956 KB Output is correct
35 Correct 97 ms 10632 KB Output is correct
36 Correct 279 ms 11904 KB Output is correct
37 Correct 662 ms 12324 KB Output is correct
38 Correct 2904 ms 15184 KB Output is correct
39 Correct 2825 ms 13936 KB Output is correct
40 Correct 304 ms 11908 KB Output is correct
41 Correct 574 ms 12376 KB Output is correct
42 Correct 1677 ms 14372 KB Output is correct
43 Correct 2682 ms 14900 KB Output is correct
44 Correct 2939 ms 14596 KB Output is correct
45 Correct 2791 ms 14340 KB Output is correct
46 Correct 767 ms 12556 KB Output is correct
47 Correct 1603 ms 13856 KB Output is correct
48 Correct 1629 ms 14252 KB Output is correct