116672024-11-04 16:55:23MagyarKendeSZLGZebra (75 pont)cpp17Wrong answer 0/751ms604 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[j - 1] != INF) {
                dp[i] = min(dp[i], dp[j - 1] + curr);
            }
        }
        cout << dp[i] << " ";
    }

    assert(dp[N] != INF);

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