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

Stella981
• 阅读 677

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就行。

代码

#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5+7;
int k1,k2,k3,n,a[maxn],dp[maxn],b[maxn],len;
void lis(){
    len=1;b[1]=a[0];
    for(int i=1;i<n;i++){
        b[len+1]=n+1;
        int l=0,r=len+1,ans=0;
        while(l<=r){
            int mid=(l+r)/2;
            if(a[i]<b[mid]){
                ans=mid;
                r=mid-1;
            }else{
                l=mid+1;
            }
        }
        b[ans]=a[i];
        if(ans>len)len++;
    }
    cout<<n-len<<endl;
}
int main(){
    scanf("%d%d%d",&k1,&k2,&k3);
    n=k1+k2+k3;
    for(int i=0;i<k1+k2+k3;i++){
        scanf("%d",&a[i]);
    }
    sort(a,a+k1);
    sort(a+k1,a+k1+k2);
    sort(a+k1+k2,a+k1+k2+k3);
    lis();
}
点赞
收藏
评论区
推荐文章
blmius blmius
3年前
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
Wesley13 Wesley13
3年前
java将前端的json数组字符串转换为列表
记录下在前端通过ajax提交了一个json数组的字符串,在后端如何转换为列表。前端数据转化与请求varcontracts{id:'1',name:'yanggb合同1'},{id:'2',name:'yanggb合同2'},{id:'3',name:'yang
皕杰报表之UUID
​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为
待兔 待兔
4个月前
手写Java HashMap源码
HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22
Jacquelyn38 Jacquelyn38
3年前
2020年前端实用代码段,为你的工作保驾护航
有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )
Stella981 Stella981
3年前
AndroidStudio封装SDK的那些事
<divclass"markdown\_views"<!flowchart箭头图标勿删<svgxmlns"http://www.w3.org/2000/svg"style"display:none;"<pathstrokelinecap"round"d"M5,00,2.55,5z"id"raphael
Wesley13 Wesley13
3年前
mysql设置时区
mysql设置时区mysql\_query("SETtime\_zone'8:00'")ordie('时区设置失败,请联系管理员!');中国在东8区所以加8方法二:selectcount(user\_id)asdevice,CONVERT\_TZ(FROM\_UNIXTIME(reg\_time),'08:00','0
Wesley13 Wesley13
3年前
00:Java简单了解
浅谈Java之概述Java是SUN(StanfordUniversityNetwork),斯坦福大学网络公司)1995年推出的一门高级编程语言。Java是一种面向Internet的编程语言。随着Java技术在web方面的不断成熟,已经成为Web应用程序的首选开发语言。Java是简单易学,完全面向对象,安全可靠,与平台无关的编程语言。
Wesley13 Wesley13
3年前
MySQL部分从库上面因为大量的临时表tmp_table造成慢查询
背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_
Python进阶者 Python进阶者
10个月前
Excel中这日期老是出来00:00:00,怎么用Pandas把这个去除
大家好,我是皮皮。一、前言前几天在Python白银交流群【上海新年人】问了一个Pandas数据筛选的问题。问题如下:这日期老是出来00:00:00,怎么把这个去除。二、实现过程后来【论草莓如何成为冻干莓】给了一个思路和代码如下:pd.toexcel之前把这