Submission #20881749


Source Code Expand

Copy
import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }


alias Item = Tuple!(int, "w", int, "v");

void main() {
  try {
    for (; ; ) {
      const N = readInt();
      const M = readInt();
      const Q = readInt();
      
      auto A = new Item[N];
      foreach (i; 0 .. N) {
        A[i].w = readInt();
        A[i].v = readInt();
      }
      auto X = new int[M];
      foreach (i; 0 .. M) {
        X[i] = readInt();
      }
      
      A.sort;
      
      foreach (q; 0 .. Q) {
        const L = readInt() - 1;
        const R = readInt();
        
        auto xs = (X[0 .. L] ~ X[R .. M]).sort.array;
        const xsLen = cast(int)(xs.length);
        auto dp = new int[][](xsLen + 1, N + 1);
        foreach (i; 0 .. xsLen + 1) foreach (j; 0 .. N) {
          if (i < xsLen) {
            chmax(dp[i + 1][j], dp[i][j]);
          }
          if (j < N) {
            chmax(dp[i][j + 1], dp[i][j]);
          }
          if (i < xsLen && j < N && xs[i] >= A[j].w) {
            chmax(dp[i + 1][j + 1], dp[i][j] + A[j].v);
          }
        }
        writeln(dp[xsLen][N]);
      }
    }
  } catch (EOFException e) {
  }
}

Submission Info

Submission Time
Task D - Shipping Center
User hos_lyric
Language D (LDC 1.20.1)
Score 400
Code Size 2319 Byte
Status AC
Exec Time 11 ms
Memory 3744 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 1
AC × 31
Set Name Test Cases
Sample sample_01.txt
All hand_01.txt, hand_02.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_31.txt, random_32.txt, random_33.txt, random_34.txt, sample_01.txt
Case Name Status Exec Time Memory
hand_01.txt AC 11 ms 3332 KB
hand_02.txt AC 3 ms 3380 KB
random_01.txt AC 4 ms 3240 KB
random_02.txt AC 4 ms 3372 KB
random_03.txt AC 3 ms 3356 KB
random_04.txt AC 4 ms 3376 KB
random_05.txt AC 4 ms 3120 KB
random_06.txt AC 3 ms 3116 KB
random_07.txt AC 4 ms 3180 KB
random_08.txt AC 5 ms 3364 KB
random_11.txt AC 5 ms 3196 KB
random_12.txt AC 3 ms 3304 KB
random_13.txt AC 4 ms 3176 KB
random_14.txt AC 4 ms 3352 KB
random_15.txt AC 3 ms 3408 KB
random_16.txt AC 4 ms 3296 KB
random_17.txt AC 4 ms 3404 KB
random_18.txt AC 4 ms 3404 KB
random_19.txt AC 3 ms 3112 KB
random_20.txt AC 4 ms 3288 KB
random_21.txt AC 3 ms 3288 KB
random_22.txt AC 6 ms 3368 KB
random_23.txt AC 3 ms 3236 KB
random_24.txt AC 5 ms 3392 KB
random_25.txt AC 4 ms 3332 KB
random_26.txt AC 4 ms 3288 KB
random_31.txt AC 4 ms 3664 KB
random_32.txt AC 4 ms 3744 KB
random_33.txt AC 9 ms 3280 KB
random_34.txt AC 5 ms 3268 KB
sample_01.txt AC 3 ms 3356 KB