116662024-11-04 16:47:54MagyarKendeSZLGZebra (75 pont)cpp17Wrong answer 0/752ms636 KiB
#include <algorithm>
#include <array>
#include <cassert>
#include <iostream>
#include <vector>

using namespace std;

const int INF = 2e9;

int main() {
    int N;
    cin >> N;

    vector<array<int, 2>> a(N + 1);
    for (int i = 1; i <= N; i++) cin >> a[i][1];
    for (int i = 1; i <= N; i++) cin >> a[i][0];
    sort(a.begin(), a.end());

    vector<int> dp(N + 1, INF);
    dp[0] = 0;

    for (int i = 1; i <= N; i++) {
        array<int, 2> cnt = {0, 0};
        int curr = 0;
        for (int j = i; j > 0; j--) {
            cnt[a[j][1]]++;
            curr += a[i][0] - a[j][0];
            if (cnt[0] && cnt[1]) {
                dp[i] = min(dp[i], dp[j - 1] + curr);
            }
        }
    }

    assert(dp[N] != INF);

    cout << dp[N] << "\n";
}
SubtaskSumTestVerdictTimeMemory
base0/75
1Accepted0/01ms508 KiB
2Wrong answer0/01ms320 KiB
3Wrong answer0/51ms320 KiB
4Wrong answer0/51ms320 KiB
5Wrong answer0/51ms320 KiB
6Wrong answer0/51ms320 KiB
7Wrong answer0/51ms320 KiB
8Wrong answer0/51ms560 KiB
9Wrong answer0/51ms320 KiB
10Wrong answer0/51ms404 KiB
11Wrong answer0/51ms320 KiB
12Wrong answer0/51ms320 KiB
13Wrong answer0/51ms636 KiB
14Wrong answer0/52ms320 KiB
15Wrong answer0/51ms320 KiB
16Wrong answer0/51ms320 KiB
17Wrong answer0/51ms320 KiB