제출 #1170908

#제출 시각아이디문제언어결과실행 시간메모리
1170908anteknneTwo Dishes (JOI19_dishes)C++20
10 / 100
990 ms44656 KiB
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

const int MAXN = 1000 * 1000 + 1;
const int MAXM = 1000 * 1000 + 1;
const int MAXN2 = 2000 + 1;
const int MAXM2 = 2000 + 1;
ll dp[MAXN2][MAXM2];
ll a[MAXN];
ll s[MAXN];
ll p[MAXN];
ll b[MAXM];
ll t[MAXM];
ll q[MAXM];
ll sprefa[MAXN];
ll sprefb[MAXM];

void rozw2 (int n, int m) {
    for (int i = 1; i <= n; i ++) {
        sprefa[i] = sprefa[i - 1] + a[i];
    }
    for (int i = 1; i <= m; i ++) {
        sprefb[i] = sprefb[i - 1] + b[i];
    }

    for (int i = 0; i <= n; i ++) {
        for (int j = 0; j <= m; j ++) {
            if (i > 0) {
                dp[i][j] = max(dp[i][j], dp[i - 1][j] + (sprefa[i] + sprefb[j] <= s[i]));
            }
            if (j > 0) {
                dp[i][j] = max(dp[i][j], dp[i][j - 1] + (sprefa[i] + sprefb[j] <= t[j]));
            }
        }
    }

    cout << dp[n][m] << "\n";
}

int main () {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int n, m;
    cin >> n >> m;

    bool rowne1 = true;
    for (int i = 1; i <= n; i ++) {
        cin >> a[i] >> s[i] >> p[i];
        if (p[i] != 1LL) {
            rowne1 = false;
        }
    }
    for (int i = 1; i <= m; i ++) {
        cin >> b[i] >> t[i] >> q[i];
        if (q[i] != 1LL) {
            rowne1 = false;
        }
    }

    if (rowne1) {
        rozw2(n, m);
        return 0;
    }



    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...