133232025-01-07 14:12:57lacitoZebra (75 pont)cpp17Accepted 75/751ms508 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
	int n; cin >> n;
	vector<int> a = {0}, b = {0};
	vector<int> dir(n);
	for (int i = 0; i < n; i++) {
		cin >> dir[i];
	}
	
	for (int i = 0; i < n; i++) {
		int x; cin >> x;
		((dir[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 time = max(a[i], b[j]);
			int awaiting = 0;
			for (int x = 0; x < i; x++) { // x ember megy meg vele
				awaiting += time - a[i - x];
				dp[i][j] = min(dp[i][j], dp[i - x - 1][j - 1] + awaiting + time - b[j]);
			}
			int bwaiting = 0;
			for (int y = 0; y < j; y++) { // y ember megy meg vele
				bwaiting += time - b[j - y];
				dp[i][j] = min(dp[i][j], dp[i - 1][j - y - 1] + time - a[i] + bwaiting);
			}
		}
	}
	cout << dp[n - 1][m - 1];
}
SubtaskSumTestVerdictTimeMemory
base75/75
1Accepted0/01ms316 KiB
2Accepted0/01ms500 KiB
3Accepted5/51ms316 KiB
4Accepted5/51ms316 KiB
5Accepted5/51ms316 KiB
6Accepted5/51ms316 KiB
7Accepted5/51ms316 KiB
8Accepted5/51ms316 KiB
9Accepted5/51ms316 KiB
10Accepted5/51ms336 KiB
11Accepted5/51ms316 KiB
12Accepted5/51ms316 KiB
13Accepted5/51ms316 KiB
14Accepted5/51ms316 KiB
15Accepted5/51ms316 KiB
16Accepted5/51ms508 KiB
17Accepted5/51ms316 KiB