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 ...
随机推荐
- mysql批量更新数据,循环select记录然后更新某一字段
-- 处理IEMI重复的历史数据,建档日期(只有年月日)倒序,档案ID倒序,根据IMEI查档案,查询的结果,相同IMEI下的第一条记录的IEMI不处理,其他的记录的imei 改为空. -- USE ` ...
- csu 1976: 搬运工小明
1976: 搬运工小明 Submit Page Summary Time Limit: 2 Sec Memory Limit: 128 Mb Submitted: 94 ...
- jquery实现比较靠谱的手风琴代码
比较靠谱的手风琴代码<pre><!DOCTYPE html><html><head> <meta charset="utf-8" ...
- mysql全量+增量备份脚本
cat xtrabackup_mysql.sh #!/bin/bash #title :xtrabackup_mysql.sh #description :backup mysql by using ...
- oracle数据恢复
比较简单的操作,如有更好的方法欢迎补充 一.查询到某个时间点删除的数据select * from table_name as of timestamp to_timestamp('2019-11-13 ...
- Dubbo2.7.3入门
2.7.X的Dubbo,包名不再是com.alibaba,而是org.apache 先看工程目录结构 一个公共api模块,一个SpringBoot项目充当Dubbo服务,一个SpringBoot项目充 ...
- Haystack搜索框架
1.什么是Haystack Haystack是django的开源全文搜索框架(全文检索不同于特定字段的模糊查询,使用全文检索的效率更高 ),该框架支持Solr,Elasticsearch,Whoosh ...
- Python3 - Bytes类型
Python3 新增 bytes 类型,是指一堆字节的集合,十六进制表现形式,两个十六进制数构成一个 byte ,以 b 开头的字符串都是 bytes 类型. 计算机只能存储二进制,字符.图片.视频. ...
- C#:蓝牙串口读数据和写数据
首次使用C#编写与COM口有关的程序,期间遇到了很多问题,写下自己的经验总结,如有错漏,欢迎批评指正! 1.新建一个串口类( SerialPort类) //Create a serial port f ...
- oracle基础知识语法大全
ORACLE支持五种类型的完整性约束NOT NULL (非空)--防止NULL值进入指定的列,在单列基础上定义,默认情况下,ORACLE允许在任何列中有NULL值.CHECK (检查)--检查在约束中 ...