codeforces1107G Vasya and Maximum Profit 【模拟】
题目分析:
前缀和啥的模拟一下就行了。
代码:
#include<bits/stdc++.h>
using namespace std; const int maxn = ; int n,x,d[maxn],sta[maxn],top;
long long minn[maxn],c[maxn],maxx[maxn]; void read(){
scanf("%d%d",&n,&x);
for(int i=;i<=n;i++) scanf("%d%lld",&d[i],&c[i]),c[i]=x-c[i];
for(int i=n;i>=;i--) d[i] -= d[i-];
} void work(){
long long ans = ;
for(int i=;i<=n;i++) ans = max(ans,c[i]);
for(int i=;i<=n;i++) c[i] = c[i-]+c[i];
maxx[] = 3e18;
for(int i=;i<=n;i++){
long long now = 2e18;
while(d[sta[top]] <= d[i]&&top>) {
now = min(minn[top],now);
top--;
}
sta[++top] = i; minn[top] = min(now,c[i-]);
maxx[top] = min(1ll*d[i]*d[i]+minn[top],maxx[top-]);
ans = max(ans,c[i]-maxx[top]);
}
printf("%lld\n",ans);
} int main(){
read();
work();
return ;
}
codeforces1107G Vasya and Maximum Profit 【模拟】的更多相关文章
- [Educational Round 59][Codeforces 1107G. Vasya and Maximum Profit]
咸鱼了好久...出来冒个泡_(:з」∠)_ 题目连接:1107G - Vasya and Maximum Profit 题目大意:给出\(n,a\)以及长度为\(n\)的数组\(c_i\)和长度为\( ...
- Codeforces 1107G Vasya and Maximum Profit 线段树最大子段和 + 单调栈
Codeforces 1107G 线段树最大子段和 + 单调栈 G. Vasya and Maximum Profit Description: Vasya got really tired of t ...
- Codeforces 1107G Vasya and Maximum Profit [单调栈]
洛谷 Codeforces 我竟然能在有生之年踩标算. 思路 首先考虑暴力:枚举左右端点直接计算. 考虑记录\(sum_x=\sum_{i=1}^x c_i\),设选\([l,r]\)时那个奇怪东西的 ...
- CodeForces 1107 - G Vasya and Maximum Profit 线段树
题目传送门 题解: 枚举 r 的位置. 线段树每个叶子节点存的是对应的位置到当前位置的价值. 每次往右边移动一个r的话,那么改变的信息有2个信息: 1. sum(a-ci) 2.gap(l, r) 对 ...
- Maximum profit of stocks
https://github.com/Premiumlab/Python-for-Algorithms--Data-Structures--and-Interviews/blob/master/Moc ...
- Yaoge’s maximum profit HDU - 5052
Yaoge’s maximum profit Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/ ...
- Maximum Profit
Maximum Profit You can obtain profits from foreign exchange margin transactions. For example, if you ...
- 【leetcode】1235. Maximum Profit in Job Scheduling
题目如下: We have n jobs, where every job is scheduled to be done from startTime[i] to endTime[i], obtai ...
- CodeForces 493B Vasya and Wrestling 【模拟】
B. Vasya and Wrestling time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
随机推荐
- vis.js 4.21.0 Timeline localization
from:http://visjs.org/timeline_examples.html https://github.com/almende/vis https://github.com/momen ...
- python地理处理包——pySAL使用
Pysal是基于Python的开源地理处理库,能提供高层次的空间分析功能.
- Android Button四种点击事件和长按事件
项目XML代码 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:andr ...
- unity can't add the script behaviour CallbackExecutor. The script needs ...
记一次Unity3D小问题 当我打开VS2017编辑完C#脚本,要将脚本拖到一个3D组件上时,发生了以下错误 unity can't add the script behaviour Callback ...
- AXI-Lite总线及其自定义IP核使用分析总结
ZYNQ的优势在于通过高效的接口总线组成了ARM+FPGA的架构.我认为两者是互为底层的,当进行算法验证时,ARM端现有的硬件控制器和库函数可以很方便地连接外设,而不像FPGA设计那样完全写出接口时序 ...
- 5.3Python数据处理篇之Sympy系列(三)---简化操作
目录 5.3简化操作 目录 前言 (一)有理数与多项式的简化 1.最简化-simplify() 2.展开-expand() 3.提公因式-factor() 4.合并同类项-ceiling() 5.简化 ...
- LeetCode算法题-Valid Palindrome II(Java实现)
这是悦乐书的第287次更新,第304篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第155题(顺位题号是680).给定非空字符串s,最多可以删除一个字符. 判断它是否是回 ...
- Bokeh
超级好用的显示图像用的package哟~~ 用法自己Google哟~ 特别喜欢这个带各种颜色的Bokeh.palette https://bokeh.pydata.org/en/latest/docs ...
- Linux搜索文件、文件夹数、文件个数命令
1.查看某文件夹下文件的个数:ls -l|grep "^-"|wc -l 2.查看某文件夹下文件目录的个数:ls -l|grep "^d"|wc -l 3.查看 ...
- Python第二天: 变量详解及变量赋值
目录 什么是变量? 怎么写一个好的变量? 下划线命名法及驼峰命名法 结语 目录 此文章针对刚学Python的小白,若觉得对变量有很好的掌握,可以观看其他的文章 在这里, 我说一下我对变量的简单总结: ...