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 ...
随机推荐
- 博弈论入门之nim游戏
更好的阅读体验点这里 nim游戏 nim游戏 有两个顶尖聪明的人在玩游戏,游戏规则是这样的: 有\(n\)堆石子,两个人可以从任意一堆石子中拿任意多个石子(不能不拿),没法拿的人失败.问谁会胜利 ni ...
- OpenCL中的half与float的转换
在kernel中使用half类型可以在牺牲一定精度的代价下来提升运算速度. 在kernel中, 可以比较方便的对half数据进行计算, 但在host上的, 对half的使用就没那么方便了. 查看cl_ ...
- Activity的启动流程
前言:新启动一个activity分为两种情况,第一种是在Launcher的桌面点击icon图标启动一个新的应用,第二种是在应用启动的情况下从OneActivity->TwoActivity 其实 ...
- idea上使用maven入门(二)——本地仓库以及使用maven
本地仓库: 首先创建完一个项目之后,点击左上角file->setting(建一个文件夹repository,建议创建到maven的外面,主要如果maven需要换版本,方便管理)如下图: ma ...
- Word Count
Word Count 一.个人Gitee地址:https://gitee.com/godcoder979/(该项目完整代码在这里) 二.项目简介: 该项目是一个统计文件字符.单词.行数等数目的应用程序 ...
- 启动期间的内存管理之pagging_init初始化分页机制--Linux内存管理(十四)
1 今日内容(分页机制初始化) 在初始化内存的结点和内存区域之前, 内核先通过pagging_init初始化了内核的分页机制. 在分页机制完成后, 才会开始初始化系统的内存数据结构(包括内存节点数据和 ...
- Linux shell 及命令汇总
1 文件管理命令 1.cat命令:将文件内容连接后传送到标准输出或重定向到文件 2.chmod命令:更改文件的访问权限 3.chown命令:更改文件的所有者 4.find命令:查找(符合条件)文件并将 ...
- tomcat+struts配置总结
忙活了好些天Tomcat和Struts配置,踩了好多坑 此文仅供参考,只是笔者自身的记录. 配置在这里就不赘述了,贴几个链接给你们参考把! 一.配置简述 jdk配置 https://blog.csdn ...
- Taro文件上传:Blob Url下载Blob对象本身并通过接口上传到服务器
最近项目的文件上传遇到一个问题,就是Taro的chooseImage传给回调的是一个Blob对象,一般来说,上传控件都会导出Data Url,而Taro给了一个Blob Url,问题在于,我直接令im ...
- 24 python初学(异常)
try, except, else, finally执行顺序:1. 先执行 try 里面的代码块,如果发生异常就会去捕获. 2. 没有错误就会执行 else 里面的信息. 3. 无论怎样都会执行 fi ...