Educational Codeforces Round 76 (Rated for Div. 2) E. The Contest dp

E. The Contest

A team of three programmers is going to play a contest. The contest consists of 𝑛 problems, numbered from 1 to 𝑛. 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 𝑎1,1,𝑎1,2,…,𝑎1,𝑘1. The second one has received problems 𝑎2,1,𝑎2,2,…,𝑎2,𝑘2. The third one has received all remaining problems (𝑎3,1,𝑎3,2,…,𝑎3,𝑘3).

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 𝑘1,𝑘2 and 𝑘3 (1≤𝑘1,𝑘2,𝑘3≤2⋅105,𝑘1+𝑘2+𝑘3≤2⋅105) — the number of problems initially taken by the first, the second and the third participant, respectively.

The second line contains 𝑘1 integers 𝑎1,1,𝑎1,2,…,𝑎1,𝑘1 — the problems initially taken by the first participant.

The third line contains 𝑘2 integers 𝑎2,1,𝑎2,2,…,𝑎2,𝑘2 — the problems initially taken by the second participant.

The fourth line contains 𝑘3 integers 𝑎3,1,𝑎3,2,…,𝑎3,𝑘3 — 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 𝑎𝑖,𝑗 meets the condition 1≤𝑎𝑖,𝑗≤𝑛, where 𝑛=𝑘1+𝑘2+𝑘3.

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 2 1 2 3 1 4 2 5 output 1 input 3 2 1 3 2 1 5 4 6 output 0 input 2 1 3 5 6 4 1 2 3 output 3 input 1 5 1 6 5 1 2 4 7 3 output 2

Note

In the first example the third contestant should give the problem 2 to the first contestant, so the first contestant has 3 first problems, the third contestant has 1 last problem, and the second contestant has 1 remaining problem.

In the second example the distribution of problems is already valid: the first contestant has 3 first problems, the third contestant has 1 last problem, and the second contestant has 2 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.

题意

现在有三个队列,每个队列都有一堆的数。现在你要使得a队列里面的数为排列的前缀,c队列的数是排列的后缀,然后b队列是其他的数。每次操作你可以让一个数到另外的队列里面去,问你最少操作多少次,能够符合需求。

题解

我们考虑排完序之后拼在一起,那么这个序列的lis,就是最后能够保持不变的。

那么nlogn跑一个lis就行。

代码

1#include<bits/stdc++.h> 2using namespace std; 3const int maxn = 2e5+7; 4int k1,k2,k3,n,a[maxn],dp[maxn],b[maxn],len; 5void lis(){ 6 len=1;b[1]=a[0]; 7 for(int i=1;i<n;i++){ 8 b[len+1]=n+1; 9 int l=0,r=len+1,ans=0; 10 while(l<=r){ 11 int mid=(l+r)/2; 12 if(a[i]<b[mid]){ 13 ans=mid; 14 r=mid-1; 15 }else{ 16 l=mid+1; 17 } 18 } 19 b[ans]=a[i]; 20 if(ans>len)len++; 21 } 22 cout<<n-len<<endl; 23} 24int main(){ 25 scanf("%d%d%d",&k1,&k2,&k3); 26 n=k1+k2+k3; 27 for(int i=0;i<k1+k2+k3;i++){ 28 scanf("%d",&a[i]); 29 } 30 sort(a,a+k1); 31 sort(a+k1,a+k1+k2); 32 sort(a+k1+k2,a+k1+k2+k3); 33 lis(); 34}
点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

皕杰报表之UUID

​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

java将前端的json数组字符串转换为列表

记录下在前端通过ajax提交了一个json数组的字符串,在后端如何转换为列表。前端数据转化与请求varcontracts{id:'1',name:'yanggb合同1'},{id:'2',name:'yanggb合同2'},{id:'3',name:'yang