题目地址: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的更多相关文章

  1. CF1119 Global Round 2

    CF1119A Ilya and a Colorful Walk 这题二分是假的.. \(1,2,1,2,1\) 有间隔为 \(3\) 的,但没有间隔为 \(2\) 的.开始被 \(hack\) 了一 ...

  2. 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-> ...

  3. Codeforces Global Round 2部分题解

    传送门 好难受啊掉\(rating\)了-- \(A\ Ilya\ and\ a\ Colorful\ Walk\) 找到最后一个与第一个颜色不同的,比一下距离,然后再找到最左边和最右边与第一个颜色不 ...

  4. Codeforces Global Round 2 题解

    Codeforces Global Round 2 题目链接:https://codeforces.com/contest/1119 A. Ilya and a Colorful Walk 题意: 给 ...

  5. Global Round 2

    A - Ilya and a Colorful Walk CodeForces - 1119A Ilya lives in a beautiful city of Chordalsk. There a ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. find mtime参数+号,-号,不带符号的用法

     find . -mtime +0 -type f -name "oms*" | xargs rm -f 删除24小时以前 oms格式的文件     #按文件更改时间来查找文件,- ...

  2. Django组件 之 分页器(paginator)

    --------------------------------------------------------------------------------路虽远,行则将至.  事虽难,做则必成. ...

  3. java基础-不用ide如何打包

    java基础-不用ide如何打包 1. 建立目录 src存放源文件 classes存放编译文件 2. 建立类文件 主类 package test.ant; import test.ant.MyTool ...

  4. 软件工程(GZSD2015) 第三次作业

    时间: 2015/4/17-2015/4/23 基本要求: 在之前编写的四则运算程序基础之上做如下改进: 请参照教材Page57:4.2-4.3节中内容,修改原程序,使之符合 "代码风格和设 ...

  5. python json数据的转换

    1  Python数据转json字符串 import json json_str = json.dumps(py_data) 参数解析: json_str = json.dumps(py_data,s ...

  6. git 原理

    1.git基本原理 2.git提交代码到远程仓库 3.远程仓库同步到本地 git pull #等同于下面命令 git fetch git merge 3.提交代码是冲突解决 一般提交前先get pul ...

  7. Manacher算法详解

    问题 什么是回文串,如果一个字符串正着度读和反着读是一样的,这个字符串就被称为回文串. such as noon level aaa bbb 既然有了回文,那就要有关于回文的问题,于是就有了-- 最长 ...

  8. spring security oauth2 client_credentials模

    spring security oauth2 client_credentials模 https://www.jianshu.com/p/1c3eea71410e 序 本文主要简单介绍一下spring ...

  9. 解决每次从cmd进入sqlplus,都得重新设置pagesize、linesize的问题

    https://blog.csdn.net/u012127798/article/details/34146143/ Oracle里的set零零碎碎的,这里整理归纳一下 SQL> set tim ...

  10. Eclipse 添加 lib (导入 .jar 包)

    1.将要添加的 jar 包直接拖到 WEB-INF/lib 目录里. 2.在项目上右键,依次选择[Build Path]--[Configure Build Path...]-- [Libraries ...