133152025-01-07 13:49:45lacitoZebra (75 pont)cpp17Accepted 75/752ms600 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() - 1;
	int m = b.size() - 1;
	vector<vector<int>> dp(n + 1, vector<int>(m + 1, 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];
				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 - x - 1][j - y - 1] + awaiting + bwaiting);
				}
			}
			// cout << dp[i][j] << " ";
		}
		// cout << "\n";
	}
	cout << dp[n][m];
}
SubtaskSumTestVerdictTimeMemory
base75/75
1Accepted0/01ms512 KiB
2Accepted0/01ms316 KiB
3Accepted5/51ms316 KiB
4Accepted5/51ms316 KiB
5Accepted5/51ms396 KiB
6Accepted5/51ms316 KiB
7Accepted5/51ms316 KiB
8Accepted5/51ms404 KiB
9Accepted5/52ms316 KiB
10Accepted5/52ms588 KiB
11Accepted5/52ms360 KiB
12Accepted5/52ms316 KiB
13Accepted5/52ms500 KiB
14Accepted5/52ms316 KiB
15Accepted5/52ms556 KiB
16Accepted5/52ms316 KiB
17Accepted5/52ms600 KiB