codeforces732D Exams(贪心+二分)
来源:互联网 发布:淘宝的欧莱雅是真的吗 编辑:程序博客网 时间:2024/05/22 17:28
题意
不可描述
思路
二分答案,贪心判断
代码
/* ********************************Author : danmuCreated Time : 2016年11月10日 星期四 10时19分02秒File Name : a.cpp******************************** */#include <algorithm>#include <iostream>#include <cstdlib>#include <cstring>#include <iomanip>#include <string>#include <vector>#include <cstdio>#include <stack>#include <queue>#include <cmath>#include <list>#include <map>#include <set>#define rep(i,x,y) for(int i=x;i<=y;++i)#define _rep(i,x,y) for(int i=x;i>=y;--i)#define CL(S,x) memset(S,x,sizeof(S))#define CP (S1,S2) memcpy(S1,S2,sizeof(S2))#define ALL(x,S) for(x=S.begin();x!=S.end();++x)#define ULL unsigned long long#define PI 3.1415926535#define INF 0x3f3f3f3f#define LL long longconst int maxn = 1e5;const int mod = 1e9 + 7;const double eps = 1e-8;using namespace std;int a[maxn+5],b[maxn+5];bool flag[maxn+5];int n,m;bool judge(int x){ LL tmp=0; memset(flag,0,sizeof flag); for(int i=x;i>=1;--i){ if(b[i]&&!flag[b[i]]){ tmp+=a[b[i]]; flag[b[i]]=true; } else if(tmp>0) --tmp; } for(int i=1;i<=m;++i) if(!flag[i]) return false; printf("%d %lld\n",x,tmp); if(tmp>0) return false; return true;}int main(){ //freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout); int l,r,mid; scanf("%d%d",&n,&m); for(int i=1;i<=n;++i) scanf("%d",b+i); for(int i=1;i<=m;++i) scanf("%d",a+i); l=0,r=n+1; while(r-l>1){ mid=(l+r)>>1; if(judge(mid)) r=mid; else l=mid; } printf("%d\n",r==n+1?-1:r); return 0;}
0 0
- codeforces732D Exams(贪心+二分)
- codeforces732D Exams(二分)
- Codeforces732D Exams
- Exams(二分求左界+贪心)
- CodeForces 732 D.Exams(二分+贪心)
- Codeforces Round #377 (Div. 2)D. Exams(二分+贪心)
- CodeForces-732D-Exams(二分 模拟 贪心)
- Exams Codeforces Round#377-D(贪心+二分)
- codeforces 732D Exams(贪心+二分)
- codeforces 732D Exams 二分搜索 贪心
- Codeforces 732D Exams【二分+贪心】
- CodeForces 732D Exams 二分+贪心
- codeforces - 732D Exams 【二分 + 贪心】
- Codeforces 732D Exams【贪心+二分】
- 【codeforces732D】二分+灵活
- Codeforces Round #377 (Div. 2) D. Exams 贪心+二分
- Codeforces Round #377 Exams(二分)
- Codeforces Round #377 D. Exams (二分)
- gnuplot 入门教程二
- CentOS 6.5 安装最新版本的php
- 内核开发之:使用图片分层技术实现窗口叠加
- Unity 保存Json数据到本地文件
- 新浪SAE python web静态文件处理
- codeforces732D Exams(贪心+二分)
- 百睿联嵌入式硬件记录
- Android检测手机锁屏以及保持屏幕常亮
- 同步与锁
- Win10 Gitblit使用笔记
- Spring在异常发生时默认的回滚策略测试
- CentOS 6.5 更新yum源
- 11月10日——离noip还有9天【你的名字……】与[一个神奇的函数]
- eval()报错 Chorme :Uncaught SyntaxError: Unexpected token{ 火狐:SyntaxError: missing ] after element lis