Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #define int long long
- #define FOR(i, a, b) for (int i = a; i <= (int) b; ++i)
- #define FORD(i, a, b) for (int i = a; i >= (int) b; --i)
- #define REP(i, a, b) for (int i = a; i < (int) b; ++i)
- using namespace std;
- typedef pair<int, int> ii;
- const int N = 2e5 + 4;
- int k[5], a[5][N], n, Pos[N], cost[N], best[N], dem[N];
- void sol() {
- FORD(i, n, 1) {
- cost[i] = cost[i+1];
- if (Pos[i] == 2) cost[i]++;
- }
- int cur = 0;
- FOR(i, 1, n+1) {
- cost[i] += cur;
- if (Pos[i] == 3) cur++;
- }
- best[n+1] = cost[n+1];
- FORD(i, n, 1) best[i] = min(best[i+1], cost[i]);
- FORD(i, n, 1) dem[i] = dem[i+1] + (Pos[i] == 1);
- int ans = (int) 1e9 + 7, res = 0;
- FOR(i, 0, n) {
- if (Pos[i] == 2) res++;
- ans = min( ans, res + dem[i+1] + best[i+1] );
- }
- cout << ans << '\n';
- }
- #undef int
- int main() {
- #define int long long
- ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
- if (fopen("input.txt", "r")) {
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- }
- cin >> k[1] >> k[2] >> k[3];
- n = k[1] + k[2] + k[3];
- FOR(id, 1, 3) FOR(i, 1, k[id]) {
- cin >> a[id][i];
- Pos[ a[id][i] ] = id;
- }
- sol();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement