Codeforces Round #560 (Div. 3) Microtransactions
Codeforces Round #560 (Div. 3)
F2. Microtransactions (hard version)
题意:
现在有一个人他每天早上获得1块钱,现在有\(n\)种商品,每种商品最后需要\(k_i\)个;现在有\(m\)个打折信息,每个打折信息包含\(d_i,t_i\),表示第\(t_i\)种商品在第\(d_i\)天打折。如果没有打折的话一个商品卖两块钱,否则卖一块钱。
现在他可以在任意一天买任意多个商品,当然钱要够用,问最少需要多少天才能把所有需要的商品买完。
题解:
其实感觉这个没有多难,二分+贪心就好了。
因为可以在任意一天买任意多个商品,那么我们只需要在每个商品打折的最后一天买就行了,这肯定是最优的。
但怎么确定这里的最后一天,二分一下就行了。答案是满足单调性质的。
代码如下:
#include <bits/stdc++.h>
#define MP make_pair
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 4e5 + 5;
int n, m;
int last[N];
vector <pii> v;
vector <int> Need, days[N];
bool check(int x) {
memset(last, 0, sizeof(last)) ;
for(int i = 0; i < m; i++) {
pii now = v[i] ;
if(now.first <= x) last[now.second] = max(last[now.second], now.first) ;
}
for(int i = 0; i <= x; i++) days[i].clear() ;
vector <int> k = Need;
for(int i = 1; i <= n; i++)
if(last[i] != 0) days[last[i]].push_back(i) ;
int money = 0;
for(int i = 1; i <= x; i++) {
money++;
if(i > 200000) {
money += x - i;
break ;
}
for(auto p : days[i]) {
if(money >= k[p]) {
money -= k[p] ;
k[p] = 0;
} else {
k[p] -= money ;
money = 0;
break ;
}
}
}
return accumulate(k.begin(), k.end(), 0) * 2 <= money ;
}
int main() {
ios::sync_with_stdio(false); cin.tie(0) ;
cin >> n >> m;
Need.push_back(0) ;
for(int i = 1; i <= n; i++){
int tmp;
cin >> tmp;
Need.push_back(tmp) ;
}
for(int i = 0; i < m; i++) {
int d, t;
cin >> d >> t;
v.push_back(MP(d, t)) ;
}
int l = 1, r = 400001, mid ;
while(l < r) {
mid = (l + r) >> 1;
if(check(mid)) r = mid ;
else l = mid + 1;
}
cout << l;
return 0;
}
Codeforces Round #560 (Div. 3) Microtransactions的更多相关文章
- A. Remainder Codeforces Round #560 (Div. 3)
A. Remainder Codeforces Round #560 (Div. 3) You are given a huge decimal number consisting of nn dig ...
- Codeforces Round #560 Div. 3
题目链接:戳我 于是...风浔凌弱菜又去写了一场div.3 总的来说,真的是比较简单.......就是.......不开long long见祖宗 贴上题解-- A 给定一个数,为01串,每次可以翻转一 ...
- Codeforces Round #560 (Div. 3)A-E
A. Remainder output standard output You are given a huge decimal number consisting of nn digits. It ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
- Codeforces Round #262 (Div. 2) 1003
Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...
随机推荐
- Android Studio 开发
Android studio安装与配置 (收藏) https://www.cnblogs.com/gufengchen/p/10991886.html ------------------------ ...
- C#中各种Lock的速度比较
简单写了个小程序,比较了一下C#中各种Lock的速度(前提是都没有进入wait状态). 各进入离开Lock 1kw次,结果如下: Lock Time (ms) No lock 58 CriticalS ...
- 湖南省第6届程序大赛第6题 Biggest Number
Problem F Biggest Number You have a maze with obstacles and non-zero digits in it: You can start fro ...
- RocketMQ 4.5.1 单机环境搭建以及生产消费测试
为了学习和方便测试,总是要启动一个单机版的.下载 http://rocketmq.apache.org/dowloading/releases/ 1. 要先配置环境变量 ROCKETMQ_HOME E ...
- CentOS 使用 prename修改文件名大小写的方法
1. CentOS和ubuntu的rename的命令是不一样的. CentOS的rename 使用的是c语言版本的 而ubuntu的rename使用的是 perl的版本,意味着很多ubuntu上面的扩 ...
- C++之开灯问题(链表)
有n盏灯,编号为1~n.第1个人把所有灯打开,第2个人按下所有编号为2的倍数开关(这些灯将被关掉),第3个人按下所有编号为3的倍数的开关,以此类推.一共有k个人,问最后有哪些灯开着?输入n和k,输出开 ...
- yzoj 2372 小B的数字 题解
题意 判断是否存在一个序列 $ b_i $ 使得 $ \prod_{i = 1}^{n} b_i | b_i^{a_i}$ 恒成立,其中 $ b_i $ 中的每个数都是2的正整数次幂. 样例输入 3 ...
- rancher部署kubernets集群
docker的安装 先添加docker源 sudo apt update sudo apt install docker.io docker更换国内镜像 1.配置脚本如下: #!/bin/bashca ...
- RHEL6.5 移植使用CentOS 的YUM 步骤
问题:使用 Red Hat Enterprise Linux Server(RHEL) yum安装软件时显示 This system is not registered with RHN. RHN s ...
- k8s 运行应用
一.deployment 创建过程 kubect创建deployment —> deployment 创建ReplicaSet—>根据ReplicaSet 创建Pod 命名方式 relic ...