School Marks CodeForces - 540B
来源:互联网 发布:淘宝发货无需物流 编辑:程序博客网 时间:2024/06/06 03:58
题意:
n个数字,已经给定k个,数字大小规定从1~P,和不可以超过x,中位数不低于y,求补全的数字
思路:
中位数小了就填y,大了就填1
#include <iostream> #include <stdio.h> #include <cstring> #include <algorithm> #include <queue> int a[10000]; int ans[10000]; using namespace std; int main() { int n,p,k,x,y; int sum=0; cin>>n>>k>>p>>x>>y; for(int i=1;i<=k;i++) { cin>>a[i]; sum+=a[i]; } sort(a+1,a+1+k); int cnt=0; for(int i=k+1;i<=n;i++) { if(a[i/2]>=y) { ans[++cnt]=1; a[i]=1; sum+=1; } else { ans[++cnt]=y; a[i]=y; sum+=y; } sort(a+1,a+1+i); } if(sum>x||a[n/2+1]<y) { cout<<-1<<endl; } else{ for(int i=1;i<=cnt;i++) cout<<ans[i]<<" "; } return 0; }
0 0
- Codeforces 540B School Marks
- CodeForces 540B School Marks
- codeforces 540B School Marks
- Codeforces 540B - School Marks
- CodeForces 540B School Marks
- School Marks CodeForces - 540B
- codeforces B. School Marks
- codeforces B. School Marks
- Codeforces 540B - School Marks (思维)
- Codeforces 540B - School Marks (贪心)
- [CodeForces 540B]School Marks[贪心]
- Codeforces 540B School Marks 【贪心构造】
- CodeForces - 540B School Marks (数学思维题 中位数)
- Codeforces Round #301 (Div. 2)B. School Marks//CodeForces - 540B 贪心
- cf 540b School Marks 贪心
- Codeforces Round #301 (Div. 2) B. School Marks(贪心)
- CF 301 B School Marks
- B. School Marks (CF #301 (Div. 2))
- animation应用
- 网络连接评分机制之再谈WIFI与数据切换过程
- Markdown 11种基本语法
- 【mysql】mysql搜索所有树形结构的节点
- 否定伪类(:not) :empty选择器
- School Marks CodeForces - 540B
- CentOS下利用mono+xsp架构asp.net环境
- 【easyui】datagrid中增加进度条
- android性能优化(一)内存优化
- easyui combobox的数据value为0时默认选择此项且提交时不会把这个0提交
- linux下php扩展curl的安装
- 【easyui】datagrid的列可编辑
- hadoop1.2.0真实集群安装
- Emgu Matrix[Double] matrix = new Matrix[Double](height, width)的简单应用