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 ...
随机推荐
- 【软件工具】ImageMagick
如何安装; 如何检查是否安装成功呢: 如何使用: https://imagemagick.org/index.php 参考 1. 官网: 完
- 【linux基础】如何配置ubuntu系统为静态IP地址
前言 连接远程server重启的时候发现IP发生变化,影响远程连接,此时,需要将server配置为静态IP. 系统环境 ubuntu16.04 操作过程 1. 设置IP和DNS command sud ...
- thinkphp3.2.2公用函数
thinkphp3.2.2公用函数函数调用默认路径 home/Common/function.php
- 学习数据结构Day1
数据结构的分类: 线性结构 数组:栈:队列:链表:哈希表:... 树结构 二叉树:二分查找树:AVL;红黑树:Treap:Splay:堆:栈:Trie:线段树:K-D树:并查集:哈夫曼 ...
- Java对象在内存的结构
一.内存布局 对象在内存中存储的结构由三部分组成:对象头.实例数据.对齐填充. 对象头 MarkWord(标记字段):哈希码.分代年龄.锁标志位.偏向线程ID.偏向时间戳等信息.Mark Word被设 ...
- Pycharm新建文件css文件无后缀,html中无法正确引入
使用pycharm新建了一个文件mycss,然后选择文件类型是css,显示也正常,但是在页面中使用link引入始终无法生效.后来加了后缀名.css,发现可以正常显示样式了,所以新建文件时最好就加上后缀 ...
- repost: Deep Reinforcement Learning
From: http://wanghaitao8118.blog.163.com/blog/static/13986977220153811210319/ accessed 2016-03-10 深度 ...
- PHP设计模式 - 解释器模式
给定一个语言, 定义它的文法的一种表示,并定义一个解释器,该解释器使用该表示来解释语言中的句子. 角色: 环境角色(PlayContent):定义解释规则的全局信息. 抽象解释器(Empress):定 ...
- 2. 运行Spark Streaming
2.1 IDEA编写程序 Pom.xml加入以下依赖: <dependency> <groupId>org.apache.spark</groupId> <a ...
- Java11新特性 - 标准Java异步HTTP客户端
Java9开始引入的一个处理 HTTP 请求的的 HTTP Client API,该 API 支持同步和异步,而在 Java 11 中已经为正式可用状态,你可以在 java.net 包中找到这个 AP ...