2018 青岛 books

books

题意:

  • 顺序从1买到n,只要钱够,就买下来。
  • 特判,richman
  • 特判,Impossible,0的数量

假设 买前m本书,显然不行,因为如果n后面有0,一定会再买。
假设 买a是0的书的数量,买前m - a本书,有没有可能第m-a-1本没买,不行,因为求的是最多钱数,如果买不起第m-a-1本,可以加钱,肯定比不买第m-a-1的方案的钱多。
为了最大化钱,还可以再加上一本书的价格-1,是哪本书呢?第m-a+1本吗?如果m-a+1大于m-a+2本呢?所以应该是剩下的书中最小的那本-1.

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
// #define int long long
#define _u_u_ ios::sync_with_stdio(false), cin.tie(nullptr)
int mod = 1e9 + 7;
const int maxn = 1e5 + 10;
const int inf = 0x3f3f3f3f;
inline void _A_A_() {
    int n, m;
    cin >> n >> m;
    vector<int> a;
    for (int i = 1;i <= n;i++) {
        int x;
        cin >> x;
        if (x != 0) a.push_back(x);
    }
    i64 ans = 0;
    int zero = n - a.size();
    if (n == m ) {
        cout << "Richman\n";
    }
    else if ((zero) > m) {
        cout << "Impossible\n";
    }
    else if (n != m) {
        for (int i = 0,cnt = 0;i < n&& cnt < (m - zero) ; i ++) {
            ans += a[i];
            cnt++;
        }
        ans += *min_element(a.begin() + m - zero, a.end());
        cout << ans - 1 << "\n";
    }
}

signed main() {
    _u_u_;
    int _o_o_ = 1;
    cin >> _o_o_;
    while (_o_o_--){_A_A_();}return 0;
}
posted @   Uzhia  阅读(14)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统
· 【译】Visual Studio 中新的强大生产力特性
· 2025年我用 Compose 写了一个 Todo App
点击右上角即可分享
微信分享提示