Educational Codeforces Round 76 (Rated for Div. 2) E 最长不下降子序列

1 篇文章 0 订阅

E. The Contest

time limit per test

2 seconds

memory limit per test

512 megabytes

input

standard input

output

standard output

A team of three programmers is going to play a contest. The contest consists of nn problems, numbered from 11 to nn. Each problem is printed on a separate sheet of paper. The participants have decided to divide the problem statements into three parts: the first programmer took some prefix of the statements (some number of first paper sheets), the third contestant took some suffix of the statements (some number of last paper sheets), and the second contestant took all remaining problems. But something went wrong — the statements were printed in the wrong order, so the contestants have received the problems in some random order.

The first contestant has received problems a1,1,a1,2,…,a1,k1a1,1,a1,2,…,a1,k1. The second one has received problems a2,1,a2,2,…,a2,k2a2,1,a2,2,…,a2,k2. The third one has received all remaining problems (a3,1,a3,2,…,a3,k3a3,1,a3,2,…,a3,k3).

The contestants don't want to play the contest before they redistribute the statements. They want to redistribute them so that the first contestant receives some prefix of the problemset, the third contestant receives some suffix of the problemset, and the second contestant receives all the remaining problems.

During one move, some contestant may give one of their problems to other contestant. What is the minimum number of moves required to redistribute the problems?

It is possible that after redistribution some participant (or even two of them) will not have any problems.

Input

The first line contains three integers k1,k2k1,k2 and k3k3 (1≤k1,k2,k3≤2⋅105,k1+k2+k3≤2⋅1051≤k1,k2,k3≤2⋅105,k1+k2+k3≤2⋅105) — the number of problems initially taken by the first, the second and the third participant, respectively.

The second line contains k1k1 integers a1,1,a1,2,…,a1,k1a1,1,a1,2,…,a1,k1 — the problems initially taken by the first participant.

The third line contains k2k2 integers a2,1,a2,2,…,a2,k2a2,1,a2,2,…,a2,k2 — the problems initially taken by the second participant.

The fourth line contains k3k3 integers a3,1,a3,2,…,a3,k3a3,1,a3,2,…,a3,k3 — the problems initially taken by the third participant.

It is guaranteed that no problem has been taken by two (or three) participants, and each integer ai,jai,j meets the condition 1≤ai,j≤n1≤ai,j≤n, where n=k1+k2+k3n=k1+k2+k3.

Output

Print one integer — the minimum number of moves required to redistribute the problems so that the first participant gets the prefix of the problemset, the third participant gets the suffix of the problemset, and the second participant gets all of the remaining problems.

Examples

input

Copy

2 1 2
3 1
4
2 5

output

Copy

1

input

Copy

3 2 1
3 2 1
5 4
6

output

Copy

0

input

Copy

2 1 3
5 6
4
1 2 3

output

Copy

3

input

Copy

1 5 1
6
5 1 2 4 7
3

output

Copy

2

Note

In the first example the third contestant should give the problem 22 to the first contestant, so the first contestant has 33 first problems, the third contestant has 11 last problem, and the second contestant has 11 remaining problem.

In the second example the distribution of problems is already valid: the first contestant has 33 first problems, the third contestant has 11 last problem, and the second contestant has 22 remaining problems.

The best course of action in the third example is to give all problems to the third contestant.

The best course of action in the fourth example is to give all problems to the second contestant.

比赛时候没有发现这些数字其实是一个排列

其实我们对每一个数的按所属的区间进行分类能找到的最长不下降子序列答案

做法很玄妙

#include<bits/stdc++.h>
using namespace std;
int a[200005];
int dp[200005];
int main()
{
    int n1,n2,n3;
    scanf("%d%d%d",&n1,&n2,&n3);
    int tmp;
    for(int i=1;i<=n1;i++)
    {
        scanf("%d",&tmp);
        a[tmp]=1;
    }
    for(int i=1;i<=n2;i++)
    {
        scanf("%d",&tmp);
        a[tmp]=2;
    }
    for(int i=1;i<=n3;i++)
    {
        scanf("%d",&tmp);
        a[tmp]=3;
    }
    int pos=0;
    for(int i=1;i<=n1+n2+n3;i++)
    {
        if(a[i]>=dp[pos])
        {
            dp[++pos]=a[i];
        }
        else
        {
            int cur=upper_bound(dp+1,dp+pos,a[i])-dp;
            dp[cur]=a[i];
        }
    }
    printf("%d\n",n1+n2+n3-pos);
}

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值