当前位置:网站首页>2022河南萌新联赛第(三)场:河南大学 A - 玉米大炮
2022河南萌新联赛第(三)场:河南大学 A - 玉米大炮
2022-07-26 04:29:00 【WA_自动机】
A - 玉米大炮
很容易发现答案具有单调性, 如果花费 x 的时间可以击溃目标, 则花费 x + 1 x + 1 x+1 的时间也可以击溃目标, 可以直接二分答案, 考虑到二分的左右区间在 [ 0 , 1 0 18 ] [0, 10^{18}] [0,1018], 对于 C + + 选手可能需要使用__int128 , 或者在二分的过程提前判断是否合法。
- 时间复杂度 O ( n × l o g ( 1 0 18 ) ) O(n × log(10^{18})) O(n×log(1018))
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 100010;
int a[N],b[N];
int n,m;
int check(LL x)
{
LL sum=0;
for(int i=1;i<=n;i++)
{
sum+=(x/b[i]+1)*a[i];
if(sum>=m) return 1;
}
return 0;
}
int main()
{
cin>>n>>m;
for(int i=1;i<=n;i++) cin>>a[i]>>b[i];
LL l=0,r=1e18;
while(l<r)
{
LL mid=(l+r)>>1;
if(check(mid)) r=mid;
else l=mid+1;
}
cout<<r<<endl;
return 0;
}
边栏推荐
猜你喜欢

Optimization analysis and efficiency execution of MySQL

MATLAB绘图

Huawei executives talk about the 35 year old crisis. How can programmers overcome the worry of age?

Getting started with mongodb Basics

Segger embedded studio cannot find xxx.c or xxx.h file

Acwing brush questions

Wu Enda's machine learning after class exercises - linear regression

第三篇如何使用SourceTree提交代码

The auxiliary role of rational cognitive educational robot in teaching and entertainment

7、 Restful
随机推荐
MySQL usage
dijango学习
dijikstra(先预处理)+dfs,relocation truncated to fit
Keil V5 installation and use
Solution: runtimeerror: expected object of scalar type int but got scalar type double
这种是我的vs没连上数据库吗
【UOJ 429】串串划分(Runs)(容斥)+ 有关 Lyndon Tree 及其应用的小小记录
Build a maker Education Laboratory for teenagers
MySQL log classification: error log, binary log, query log, slow query log
MySQL only checks the reasons for the slow execution of one line statements
What if win11 cannot wake up from sleep? Solution of win11 unable to wake up during sleep
UE4 键盘控制开关灯
Phaser(一):平台跳跃收集游戏
Can literature | relationship research draw causal conclusions
Graph theory: topological sorting
Tutorial on using the one click upgrade function of the rtsp/onvif protocol video platform easynvr service
Network Security Learning - permission promotion 2
使用百度飞桨EasyDL完成垃圾分类
建设面向青少年的创客教育实验室
When you try to delete all bad code in the program | daily anecdotes