边缘世界:轨道交易 题目解析

题目

题解

由于题目明确可以找零,说明无论如何,只要我们现有总金额大于商品价格,我们就可以购买这个商品,因此题目可以简述为,给定总金额和若干商品的价格,问最多可以买多少件商品,因此我们只需要尽可能买便宜的商品从而最大化购买的商品数量。

#include <bits/stdc++.h>

using i128 = __int128;
using ll = long long;
using ull = unsigned long long;
using de = double;
using ld = long double;
using namespace std;

void solve()
{
    int n, m; cin >> n >> m;
    vector<int> p(n); for (int i = 0; i < n; ++i) cin >> p[i];
    sort(p.begin(), p.end());
    
    ll money = 0;
    for (int i = 0; i < m; ++i)
    {
        int x, c; cin >> x >> c;
        money += (1LL << x) * c; // 1LL << x 相当于 2^x
    }

    int ans = 0;
    for (int i = 0; i < n; ++i)
    {
        if (money < p[i]) break;

        money -= p[i];
        ans++;
    }

    cout << ans;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int t = 1;
    // cin >> t;

    while (t--)
    {
        solve();
    }
}
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇