CF1119B Alyona and a Narrow Fridge

Posted xht37

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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的主要内容,如果未能解决你的问题,请参考以下文章

CF739B Alyona and a tree

CF | Alyona and Numbers

cf682E Alyona and Triangles

CF#358 D. Alyona and Strings DP

B. Alyona and a tree

Alyona and a tree (树上倍增+差分)