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个英雄,每个英雄有两种属性(分别为攻击力,和可攻击次数),当安排最好的情况下,最少的天数(每选择一个英雄出战就是一天) 思路:因为怪兽是不 ...
随机推荐
- 一些好用的Jquery插件
1.jquery.resizableColumns.min.js,可以给table列加上调节宽度的功能 2.Jquery.cookie.js,可以在客户端写入和获取cookie 3.Paginatio ...
- python使用临时文件
# 需求 # 某项目中,我们从传感器中采集数据,没采集1G数据后,做数据分析,最终只保存分析结果 # 这样很大的临时文件如果常驻在内存,将消耗大量地内存资源,我们可以使用临时文件储存(外部储存) # ...
- Android 开发 微信分享,登陆,获取信息
1 获取appid和appsecret. https://open.weixin.qq.com/cgi-bin/index?t=home/index&lang=zh_CN ...
- python3练习100题——016
今天的题目比较容易了,旨在让人掌握datetime模块下的一些用法. 链接:http://www.runoob.com/python/python-exercise-example16.html 题目 ...
- Codeforces Hello2020 A-E简要题解
contest链接:https://codeforces.com/contest/1284 A. New Year and Naming 思路:签到,字符串存一下,取余拼接. #include< ...
- HTML列表标签
<ul>无序列表 有2个属性 1.compact 属性: 规定列表呈现的效果比正常情况更小巧.没啥作用 2.type 属性 disc小圆点 square小方块 circle小圆圈(默认) ...
- python 数据模型orm
在__init__.py增加,因为默认的mysqldb不支持python3 import pymysql pymysql.install_as_MySQLdb() 创建表 from django.db ...
- THINKCMF5 部署到 Windows服务器
问题一 [public/index.php是项目的入口文件,请配置服务器时把 public 目录做为 web 目录]这是官方文档的一句话.如何将public 目录做为 web 目录? 解答:在IIS或 ...
- bzoj4199: [Noi2015]品酒大会 (并查集 && 后缀数组)
据说用后缀自动机 + dp也能做 然而并不会 后缀数组的做法呢 就是先建个后缀数组,求出height值,此时如果直接找,复杂度是n ^ 2的,肯定会超时. 但是height大的值是不会对小的产生影响的 ...
- Spark 中 GroupByKey 相对于 combineByKey, reduceByKey, foldByKey 的优缺点
避免使用GroupByKey 我们看一下两种计算word counts 的方法,一个使用reduceByKey,另一个使用 groupByKey: val words = Array("on ...