Educational Codeforces Round 76 (Rated for Div. 2)E(最长上升子序列)
#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
int a[200007],b[200007],c[200007];
int cnt1[200007],cnt2[200007],cnt3[200007];
int mn[200007];
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int k1,k2,k3;
cin>>k1>>k2>>k3;
for(int i=1;i<=k1;++i){
cin>>a[i];
++cnt1[a[i]];
}
for(int i=1;i<=k2;++i){
cin>>b[i];
++cnt2[b[i]];
}
for(int i=1;i<=k3;++i){
cin>>c[i];
++cnt3[c[i]];
}
int n=k1+k2+k3;
for(int i=1;i<=n;++i){
cnt1[i]=cnt1[i-1]+cnt1[i];//小于等于i的个数
cnt2[i]=cnt2[i-1]+cnt2[i];
cnt3[i]=cnt3[i-1]+cnt3[i];
}
for(int i=0;i<=n;++i)
mn[i]=cnt3[i]-cnt2[i];
for(int i=n-1;i>=0;--i)
mn[i]=min(mn[i+1],mn[i]);
int ans=1e9;
for(int i=0;i<=n;++i)
ans=min(ans,cnt2[i]-cnt1[i]+mn[i]+cnt1[n]+cnt2[n]);
/*
假设最终状态为第一个人有0~i,第二个人有i+1~j,第三个人有j+1~n
那么最小操作数等于第二个人和第三个人拥有的1~i个数加上第一个人和第三个人拥有的i+1~j个数加上第一个人和第二个人拥有的j+1~n个数
即cnt2[i]+cnt3[i]+cnt1[j]-cnt1[i]+cnt3[j]-cnt3[i]+cnt1[n]-cnt1[j]+cnt2[n]-cnt2[j]
化简为cnt2[i]-cnt1[i]+cnt3[j]-cnt2[j]+cnt1[n]+cnt2[n]
从0到n枚举i,只剩下cnt3[j]-cnt2[j]一个变量
维护一个后缀数组mn[i]表示[i,n]中最小的cnt3[j]-cnt2[j]
*/
cout<<ans;
return 0;
}
Educational Codeforces Round 76 (Rated for Div. 2)E(最长上升子序列)的更多相关文章
- Educational Codeforces Round 76 (Rated for Div. 2) E. The Contest
Educational Codeforces Round 76 (Rated for Div. 2) E. The Contest(dp+线段树) 题目链接 题意: 给定3个人互不相同的多个数字,可以 ...
- Educational Codeforces Round 76 (Rated for Div. 2)E(dp||贪心||题解写法)
题:https://codeforces.com/contest/1257/problem/E 题意:给定3个数组,可行操作:每个数都可以跳到另外俩个数组中去,实行多步操作后使三个数组拼接起来形成升序 ...
- Educational Codeforces Round 76 (Rated for Div. 2)
传送门 A. Two Rival Students 签到. Code /* * Author: heyuhhh * Created Time: 2019/11/13 22:37:26 */ #incl ...
- 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
- Educational Codeforces Round 76 (Rated for Div. 2) D. Yet Another Monster Killing Problem 贪心
D. Yet Another Monster Killing Problem You play a computer game. In this game, you lead a party of
- Educational Codeforces Round 76 (Rated for Div. 2) C. Dominated Subarray 水题
C. Dominated Subarray Let's call an array
- Educational Codeforces Round 76 (Rated for Div. 2) B. Magic Stick 水题
B. Magic Stick Recently Petya walked in the forest and found a magic stick. Since Petya really likes ...
- Educational Codeforces Round 76 (Rated for Div. 2) A. Two Rival Students 水题
A. Two Rival Students There are
- Educational Codeforces Round 76 (Rated for Div. 2) D题
题意: 给你n个关卡,每个关卡有一个怪物,怪物的攻击力为a[i],你有n个英雄,每个英雄有一个攻击力,和疲劳值,只要英雄的攻击力比怪物的高就算打过了,同时疲劳减一,一天只能出战一个英雄,一个英雄可以打 ...
- Educational Codeforces Round 76 (Rated for Div. 2) D
D题 原题链接 题意:就是给你n个怪兽有一个属性(攻击力),m个英雄,每个英雄有两种属性(分别为攻击力,和可攻击次数),当安排最好的情况下,最少的天数(每选择一个英雄出战就是一天) 思路:因为怪兽是不 ...
随机推荐
- 训练20191007 2017-2018 ACM-ICPC Latin American Regional Programming Contest
2017-2018 ACM-ICPC Latin American Regional Programming Contest 试题地址:http://codeforces.com/gym/101889 ...
- PP: Data-driven classification of residential energy consumption patterns by means of functional connectivity networks
Purpose Implement a good user aggregation and classification. or to assess the interrelation pattern ...
- cadence动态铜皮的参数设置
注意这幅图和上一幅图那个焊盘距离shape的间距,变大了,这个设置很用的.
- js清空子节点
删除全部子节点 function removeAllChild(){ var div = document.getElementById("div1"); while(div.ha ...
- [Luogu]三步必杀
Description Luogu4231 Solution 我最近到底怎么了,这种题都做不出来了,一看题第一反应李超线段树(虽然不会),觉得不可做,看一眼题解才发现这个题可以差分,然后差分还打错了好 ...
- python pymysql 基本使用
from pymysql import * # 1.创建连接数据库 conn = connect(host="localhost", port=3306, user="r ...
- C++-POJ3349-Snowflake Snow Snowflakes[STL][set][hash未写]
错误AC解法,sort+set判重,为考虑异构! 比较坑的一点是读入时scanf一定要一次读6个数,不然会TLE #include <set> #include <map> # ...
- HTML学习(7)格式化标签
对文本格式进行编辑的标签.常用: <b>加粗文本</b> <strong>加重语气</strong> 与<b>效果一样,<stro ...
- 线段树 区间查询区间修改 poj 3468
#include<cstdio> #include<iostream> #include<algorithm> #include<string.h> u ...
- Homebrew安装和Mac使用
软件安装 1.Homebrew安装 ruby环境: curl -sSL https://get.rvm.io | bash -s stable 官网方式: /usr/bin/ruby -e & ...