747D. Winter Is Coming
从前到后找出连续两个负数的距离,然后贪心枚举一下,注意要特别判断最后的情况 因为不需要再换回去了
//cyc
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,a,n) for(int i=n;i>=a;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mst(a) memset(a,0x3f3f3f3f,sizeof a)using namespace std;
typedef pair<int,int> pii;
const int maxn=2e5+5;
int t[maxn];int main()
{ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);int n,k;cin>>n>>k;int cnt=0;vector<int> dis;int prev=0;int ans=0;for(int i=1;i<=n;i++){cin>>t[i];if(t[i]<0){cnt++;dis.pb(i-prev-1);prev=i;}}if(prev)dis.pb(n-prev);if(cnt>k){cout<<-1<<endl;return 0;}if(cnt==0){cout<<0<<endl;return 0;}int p;k-=cnt;p=dis.size();ans=p*2-2;sort(dis.begin()+1,dis.end()-1);// for(int i=0;i<p;i++)cout<<dis[i]<<" ";// cout<<endl;for(int i=1;i<p-1;i++){//cout<<dis[i]<<endl;if(k>=dis[i]){k-=dis[i];ans-=2;}else break;}if(k>=dis[p-1]){ans--;k-=dis[p-1];}cout<<ans<<endl;
}
747D. Winter Is Coming相关推荐
- CodeForces - 747D Winter Is Coming(xjb乱搞)
题目链接:http://codeforces.com/problemset/problem/747/D点击打开链接 D. Winter Is Coming time limit per test 1 ...
- linux离线配置qt环境,Linux下配置QT环境
一.下载Qt源码包到本机,然后解压缩 #tar zxvf qt-x11-opensource-src-4.3.2.tar.gz -C /usr/local //将qt-x11-opensource-s ...
- [题解]CF Round #386 (Div.2)
747A:Display Size 题意简述 给你 n n,求一对x,yx,y使得 x∗y=n x \ast y=n并且 x,y x,y最接近. 数据范围 n≤106 n \leq 10^6 思路 从 ...
- 【笔记】重学前端-winter
本文为:winter 发布在极客时间 [重学前端]系列课程的的笔记和总结 支持正版哦: https://time.geekbang.org/col... 导语 如果深入进去了解,你会发现,表面上看他们 ...
- “计算机之子”winter:我的前端学习路线与方法
你好,我是winter.今天我们一起来聊聊前端的学习路线与方法. 到现在为止,前端工程师已经成为研发体系中的重要岗位之一.可是,与此相对的是,我发现极少或者几乎没有大学的计算机专业愿意开设前端课程,更 ...
- 寒冬 winter:代码无捷径,只怕有心人
2018年初冬,在淘宝996乐队的<持续迭代>的余味中,winter 在 Vue Conf 上以"挖掘 Vue 的声明式交互能力"为题做了演讲 winter,本名程劭非 ...
- python使用matplotlib可视化、使用matplotlib可视化scipy.misc图像、自定义使用winter色彩映射、将不同亮度映射到不同的色彩
python使用matplotlib可视化.使用matplotlib可视化scipy.misc图像.自定义使用winter色彩映射.将不同亮度映射到不同的色彩 目录
- 2015 UESTC Winter Training #10【Northeastern Europe 2009】
2015 UESTC Winter Training #10 Northeastern Europe 2009 最近集训都不在状态啊,嘛,上午一直在练车,比赛时也是刚吃过午饭,状态不好也难免,下次比赛 ...
- CodeForces 839D - Winter is here | Codeforces Round #428 (Div. 2)
赛后听 Forever97 讲的思路,强的一匹- - /* CodeForces 839D - Winter is here [ 数论,容斥 ] | Codeforces Round #428 (Di ...
最新文章
- node版本升级for ubuntu
- Hdu 1217 最短路.cpp
- 利用GPU训练网络时遇到的一些问题
- java安全沙箱(一)之ClassLoader双亲委派机制
- typescript入门简明教程
- python开发笔记软件_图解Python编程神器Jupyter Notebook
- 基础算法 —— 递归/递推 —— 汉诺塔问题(Hanoi)
- 电脑静音工作,又听不到12306的来票音乐,纠结啊 !但春节前工作多任务重,不能安心工作,就动手做个“无声购票弹窗”工具吧!...
- 互联⽹名词⼤全——商业模式篇
- vassistx插件
- python链式函数_python 链式
- HTML页面悬浮球,html滑动仿悬浮球菜单
- The software-quanlity landscape -- Code complete reading notes
- leetcode:Permutations1+2nbsp;+nbsp;Rotat…
- 阅读text2sql论文《RAT-SQL: Relation-Aware Schema Encoding and Linking for Text-to-SQL Parsers》
- 姊妹篇:我是一块声卡
- nginx的入门使用(搭建本地的网站服务)
- 多目标优化蚁群算法的matlab_混合参数蚁群算法的改进优化
- Android MVVM框架搭建(二)OKHttp + Retrofit + RxJava
- Java随机生成四位数字(四位整数)Random类