256452026-02-23 21:54:20anonSzámsorjáték (40 pont)cpp17Accepted 40/40209ms1200 KiB
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define FastIO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
typedef long long ll;
const ll INF = (1LL << 62);
int main() {
    FastIO;
    ll i, j, N, M, K;
    cin >> N >> M >> K;
    vector<ll> A(N);
    for(i = N - 1; i >= 0; i--)
        cin >> A[i];
    vector<ll> B(M);
    for(i = M - 1; i >= 0; i--)
        cin >> B[i];
    vector<array<ll, 3>> Q(K);
    for(i = 0; i < K; i++) {
        cin >> Q[i][0] >> Q[i][1];
        Q[i][0] = N - Q[i][0] + 1;
        Q[i][1] = M - Q[i][1] + 1;
        Q[i][2] = i;
    }
    sort(all(Q));
    vector<ll> ans(K);
    vector<vector<array<ll, 2>>> dp(2, vector<array<ll, 2>>(M + 1));
    dp[0][0][1] = 0;
    i = 0;
    for(const auto &x : Q) {
        while(i <= x[0]) {
            for(j = !i; j <= M; j++) {
                dp[i&1][j][0] = max(i ? (A[i - 1] + dp[1-i&1][j][1]) : 0, max(j ? (B[j - 1] + dp[i&1][j - 1][1]) : 0, (i && j) ? (A[i - 1] + B[j - 1] + dp[1-i&1][j - 1][1]) : 0));
                dp[i&1][j][1] = min(i ? dp[1-i&1][j][0] : INF, min(j ? dp[i&1][j - 1][0] : INF, (i && j) ? dp[1-i&1][j - 1][0] : INF));
            }
            i++;
        }
        ans[x[2]] = dp[x[0]&1][x[1]][0];
    }
    for(const auto &x : ans)
        cout << x << '\n';
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base40/40
1Accepted0/01ms500 KiB
2Accepted0/041ms564 KiB
3Accepted1/12ms316 KiB
4Accepted1/11ms316 KiB
5Accepted1/11ms316 KiB
6Accepted1/14ms316 KiB
7Accepted1/11ms316 KiB
8Accepted1/12ms316 KiB
9Accepted1/12ms508 KiB
10Accepted1/12ms316 KiB
11Accepted1/13ms316 KiB
12Accepted1/13ms568 KiB
13Accepted1/19ms652 KiB
14Accepted1/19ms548 KiB
15Accepted1/110ms516 KiB
16Accepted1/18ms516 KiB
17Accepted2/2185ms760 KiB
18Accepted2/2182ms796 KiB
19Accepted2/2189ms828 KiB
20Accepted2/2197ms1076 KiB
21Accepted2/2182ms1076 KiB
22Accepted2/2201ms1200 KiB
23Accepted3/3209ms1076 KiB
24Accepted3/3206ms1060 KiB
25Accepted4/4209ms1080 KiB
26Accepted4/4193ms1076 KiB