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 ...
随机推荐
- zabbix,php,nginx,mysql源码安装 神仙操作
→软件包 mkdir /soft/ cd /soft ♦下载以下软件包 nginx-1.14.2.tar.gz wget http://nginx.org/download/nginx-1.14.2. ...
- DeeplabV3+ 命令行不显示miou的解决
首先看到训练时会在命令行里输出 loss 和 total loss,那是怎么做到的呢,通过分析 train.py 源码,看到如下代码 total_loss = tf.cond( should_log, ...
- Skyline 7 版本TerraExplorer Pro二次开发快速入门
年底了,给大家整理了一下Skyline 7版本的二次开发学习初级入门教程,献给那些喜欢学习的年轻朋友. 我这整理的是Web控件版本的开发示例,里面页面代码保存成html,都可以直接运行的. 测试使用的 ...
- 查看Android系统已安装应用的列表
可以通过adb shell pm list package 我们可以通过系统提供的工具pm来隐藏一些应用,比如:pm hide和pm disable pm disable <PACKAGE_OR ...
- 关于rem布局
实际UI设计稿给过来为了在手机屏幕上显示清晰,设计稿通常为实际标准手机页面的2倍,一般为640px(以ip5的屏幕尺寸320px设计)或者750px(以ip6的屏幕尺寸为375px设计),这是前提. ...
- 启动jar的方式
1.windows server 2008 start "srvRegistry" java -jar srvRegistry-1.0-SNAPSHOT.jar --spring. ...
- BZOJ3498PA2009 Cakes——三元环
题目描述 N个点m条边,每个点有一个点权a.对于任意一个三元环(j,j,k)(i<j<k),它的贡献为max(ai,aj,ak) 求所有三元环的贡献和.N<100000,,m< ...
- mpvue——引入echarts打包vendor过大
前言 有一个项目需要引入图表,当时有两种选择一种是mpvue-echarts,一种是F2,而我经过踩坑之后依然决然的选择了mpvue-echarts,简单快捷容易上手,主要之前用过比较熟悉. 问题 | ...
- Magento CURD
创建数据库表 创建模型-CRUD模型Model是MVC架构的一条巨大路径.在Magento 2 CRUD中,模型具有许多不同的功能,例如管理数据,安装或升级模块.在本教程中,我只讨论数据管理CRUD. ...
- gcc __thread关键字
https://blog.csdn.net/xj178926426/article/details/54345449 EventLoop.cpp __thread EventLoop* t_loopI ...