2023.6.21 每日一题

原题链接

A: Wunder Fund Round 2016 (Div. 1 + Div. 2 combined) - F

B: Codeforces Round 727 (Div. 2) - D

B. PriceFixed - 1600

题目大意

商店里有 n 个商品,价格为 2,至少要买第 i 件商品 ai 个,同时如果我们总共买了超过 bi 件商品,那么第 i 件商品打五折。问至少要花多少钱。

解题思路

直接贪心,将商品按照 bi 从大到小排序。不考虑打折来买就是我们钱数的上界 2×n,我们考虑什么时候可以节省一部分钱,就是我们对一件商品花钱花到打折的时候,这件商品能打折并且总共花的钱少于我们不打折不多买花的钱。注意要按照我们对 bi 排序的顺序,bi 大的先考虑,才能保证贪心成立。

AC Code

#include <iostream> #include <algorithm> #include <cstring> #include <cmath> #define endl '\n' #define ios ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr) using namespace std; typedef long long LL; typedef unsigned long long ULL; const int N = 4e5 + 10; const int MOD = 1e9 + 7; pair<LL, LL> p[N]; int idx[N]; bool cmp(int x, int y) { return p[x].second > p[y].second; } void solve() { int n; cin >> n; LL sum = 0; for (int i = 1; i <= n; ++i) { LL x, y; cin >> x >> y; p[i] = {x, y}; sum += x; idx[i] = i; } sort(idx + 1, idx + n + 1, cmp); LL res = sum << 1; for (int i = 1; i <= n; ++i) { int id = idx[i]; LL max_ = max(0ll, min(sum - p[id].second, p[id].first)); res -= max_; sum -= max_; } cout << res << endl; } signed main() { ios; int T = 1; // cin >> T; while (T--) { solve(); } }

__EOF__

本文作者叁纔
本文链接https://www.cnblogs.com/SanCai-Newbie/p/17496555.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角推荐一下。您的鼓励是博主的最大动力!
posted @   叁纔  阅读(29)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
点击右上角即可分享
微信分享提示