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 ...
随机推荐
- webpack中插件 prerender-spa-plugin 来进行SEO优化(二十四)
vue.react对于开发单页应用来说带来了很好的用户的体验,但是同样有缺点,比如首页加载慢,白屏或SEO等问题的产生.为什么会出现这种情况呢?我们之前开发单页应用是这样开发的,比如首页 index. ...
- 基于aws api gateway的asp.net core验证
本文是介绍aws 作为api gateway,用asp.net core用web应用,.net core作为aws lambda function. api gateway和asp.net core的 ...
- 5-STM32物联网开发WIFI(ESP8266)+GPRS(Air202)系统方案数据篇(配置保存数据的数据库)
配置信息如下:这是我的python软件和APP软件默认连接的配置 数据库名称:iot 编码utf8 表格名字:historicaldata 字段 id 自增,主键 date ...
- asp.net webapi中helppage
今天研究了下webapi,发现还有自动生成接口说明文档提供测试的功能 参考:https://docs.microsoft.com/en-us/aspnet/web-api/overview/getti ...
- Java的selenium代码随笔(5)
//以下七种方法主要用于生成年.月.日.小时.分钟和秒的信息,用于生成保存截图的文件目录名和文件名/** 格式化输出日期* * @return 返回字符型日期*/public static Strin ...
- 前后端不分离的springboot项目问题:页面框架问题
前言:最近自己想搞一个以springboot开发的web项目,由于页面布局问题,在前期开发的时候没有太注意,每天写一点现在开发到一半出现了一个大问题. 1.先说说整个网站框架搭建问题:(整个项目前后端 ...
- Lodop条形码竖条和值右端不对齐的解决方法
当Lodop条形码设置的宽度比较短,数值比较多的时候,会出现条码的竖条和右端不对齐.个人测试了一下,发现解决办法有三种:1.增加条形码的宽度.2.隐藏条码本身的值,用text文本代替.3.修改条形码下 ...
- python基础4 列表和元组
一. 列表列表:python基础数据类型之一:其他语言中也有列表的概念,js 数组,可索引,可切片,可加步长li = ['hello', 100, True, [1, 2, 3], {'name':' ...
- BZOJ4241历史研究——回滚莫队
题目描述 IOI国历史研究的第一人——JOI教授,最近获得了一份被认为是古代IOI国的住民写下的日记.JOI教授为了通过这份日记来研究古代IOI国的生活,开始着手调查日记中记载的事件. 日记中记录了连 ...
- Codeforce Round #554 Div.2 C - Neko does Maths
数论 gcd 看到这个题其实知道应该是和(a+k)(b+k)/gcd(a+k,b+k)有关,但是之后推了半天,思路全无. 然而..有一个引理: gcd(a, b) = gcd(a, b - a) = ...