138392025-01-08 21:04:54sarminZebra (75 pont)cpp17Accepted 75/752ms508 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int n; cin >> n;
	vector<int> a = {0}, b = {0};
	vector<int> type(n);
	for (int i = 0; i < n; i++) {
        cin >> type[i];
	}

	for (int i = 0; i < n; i++) {
        int x; cin >> x;
        ((type[i] == 0) ? a : b).push_back(x);
	}

	n = a.size(); int m = b.size();
	vector<vector<int>> dp(n, vector<int>(m, 1e9));
	dp[0][0] = 0;
	for (int i = 1; i < n; i++) {
        for (int j = 1; j < m; j++) {
            int mxT = max(a[i], b[j]);
            int await = 0, bwait = 0;
            for (int k = 0; k < i; k++) {
                await += mxT - a[i - k];
                dp[i][j] = min(dp[i][j], dp[i - k - 1][j - 1] + await + mxT - b[j]);
            }

            for (int k = 0; k < j; k++) {
                bwait += mxT - b[j - k];
                dp[i][j]= min(dp[i][j], dp[i - 1][j - k - 1] + bwait + mxT - a[i]);
            }
        }
	}
	cout << dp[n - 1][m - 1];

	return 0;
}
SubtaskSumTestVerdictTimeMemory
base75/75
1Accepted0/01ms316 KiB
2Accepted0/01ms316 KiB
3Accepted5/51ms316 KiB
4Accepted5/51ms508 KiB
5Accepted5/52ms316 KiB
6Accepted5/51ms316 KiB
7Accepted5/51ms316 KiB
8Accepted5/51ms316 KiB
9Accepted5/51ms316 KiB
10Accepted5/51ms316 KiB
11Accepted5/51ms316 KiB
12Accepted5/51ms500 KiB
13Accepted5/51ms316 KiB
14Accepted5/51ms316 KiB
15Accepted5/51ms316 KiB
16Accepted5/51ms316 KiB
17Accepted5/51ms316 KiB