CF1119B Alyona and a Narrow Fridge
题目地址:CF1119B Alyona and a Narrow Fridge
\(O(n^2)\) 暴力枚举+贪心
从小到大枚举答案
假设枚举到 \(i\) ,将 \(a_1\) 到 \(a_i\) 排序,从大到小贪心的放。
如果高度超过给定的高度,答案为 \(i-1\) 。
如果一直到 \(n\) 都没超过,答案为 \(n\) 。
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll N = 1e3 + 6;
ll n, m, a[N], b[N];
int main() {
cin >> n >> m;
for (ll i = 1; i <= n; i++) scanf("%lld", &a[i]);
for (ll i = 1; i <= n; i++) {
for (ll j = 1; j <= i; j++)
b[i] = a[i];
sort(b + 1, b + i + 1);
ll now = 0;
for (ll j = i; j > 0; j -= 2) {
now += b[j];
}
if (now > m) {
cout << i - 1 << endl;
return 0;
}
}
cout << n << endl;
return 0;
}
CF1119B Alyona and a Narrow Fridge的更多相关文章
- CF1119 Global Round 2
CF1119A Ilya and a Colorful Walk 这题二分是假的.. \(1,2,1,2,1\) 有间隔为 \(3\) 的,但没有间隔为 \(2\) 的.开始被 \(hack\) 了一 ...
- Codeforces Global Round 2 Solution
这场题目设置有点问题啊,难度:Div.2 A->Div.2 B->Div.2 D->Div.2 C->Div.2 D->Div.1 D-> Div.1 E-> ...
- Codeforces Global Round 2部分题解
传送门 好难受啊掉\(rating\)了-- \(A\ Ilya\ and\ a\ Colorful\ Walk\) 找到最后一个与第一个颜色不同的,比一下距离,然后再找到最左边和最右边与第一个颜色不 ...
- Codeforces Global Round 2 题解
Codeforces Global Round 2 题目链接:https://codeforces.com/contest/1119 A. Ilya and a Colorful Walk 题意: 给 ...
- Global Round 2
A - Ilya and a Colorful Walk CodeForces - 1119A Ilya lives in a beautiful city of Chordalsk. There a ...
- Codeforces Round #381 (Div. 2)D. Alyona and a tree(树+二分+dfs)
D. Alyona and a tree Problem Description: Alyona has a tree with n vertices. The root of the tree is ...
- Codeforces Round #381 (Div. 2)C. Alyona and mex(思维)
C. Alyona and mex Problem Description: Alyona's mother wants to present an array of n non-negative i ...
- Codeforces Round #381 (Div. 2)B. Alyona and flowers(水题)
B. Alyona and flowers Problem Description: Let's define a subarray as a segment of consecutive flowe ...
- Codeforces Round #381 (Div. 2)A. Alyona and copybooks(dfs)
A. Alyona and copybooks Problem Description: Little girl Alyona is in a shop to buy some copybooks f ...
随机推荐
- THUWC2019:Reach out
竟然还有机会去THUWC!!! 不过没有上WC线感觉有点可惜-- Day -INF~Day -2 考完NOIP两周滚回来被神仙们吊打 先是做专题,为什么会选到构造啊(ノ`Д)ノ 我构造专题有7道题留作 ...
- js字符串转时间
function StrToDateTime(value) { if (value) { return (new Date(Date.parse(value.replace(/-/g, "/ ...
- svn 钩子应用 - svn 提交字符限制, 不能为空
一.版本库钩子 1.1 start-commit 开始提交的通知 输入参数:传递给你钩子程序的命令行参数,顺序如下: 1. 版本库路径 2. 认证过的尝试提交的用户名 3. Depth,mer ...
- Centos6.6安装docker
今天在虚拟机上体验一下docker, 操作系统:Centos6.6 内核版本:2.6 1. https://download.csdn.net/download/dujiaoyang000/10872 ...
- HTML之表格
表格标签和表格标题 表格标签 <table> <tr> <td></td> ...... </tr> <tr> <td&g ...
- redis info
redis命令详细文档可参考:http://redisdoc.com/index.html info命令显示redis详细的状态信息. 命令的基本用法有三种: 1)info:部分redis状态统计信息 ...
- Flutter之Color
color:颜色Colors.green ,系统默认了几种颜色,分别如下: red, pink, purple, deepPurple, indigo, blue, lightBlue, cyan, ...
- nginx.conf配置详解
######Nginx配置文件nginx.conf中文详解##### #定义Nginx运行的用户和用户组 user www www; #nginx进程数,建议设置为等于CPU总核心数. worker_ ...
- python之数据类型补充、集合、深浅copy
一.内容回顾 代码块: 一个函数,一个模块,一个类,一个文件,交互模式下,每一行就是一个代码块. is == id id()查询对象的内存地址 == 比较的是两边的数值. is 比较的是两边的内存地址 ...
- SPOJ-LCS Longest Common Substring 【后缀自动机】
题目分析: 用没出现过的字符搞拼接.搞出right树,找right集合的最小和最大.如果最小和最大分居两侧可以更新答案. 代码: #include<bits/stdc++.h> using ...