题目分析:

前缀和啥的模拟一下就行了。

代码:

 #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 【模拟】的更多相关文章

  1. [Educational Round 59][Codeforces 1107G. Vasya and Maximum Profit]

    咸鱼了好久...出来冒个泡_(:з」∠)_ 题目连接:1107G - Vasya and Maximum Profit 题目大意:给出\(n,a\)以及长度为\(n\)的数组\(c_i\)和长度为\( ...

  2. Codeforces 1107G Vasya and Maximum Profit 线段树最大子段和 + 单调栈

    Codeforces 1107G 线段树最大子段和 + 单调栈 G. Vasya and Maximum Profit Description: Vasya got really tired of t ...

  3. Codeforces 1107G Vasya and Maximum Profit [单调栈]

    洛谷 Codeforces 我竟然能在有生之年踩标算. 思路 首先考虑暴力:枚举左右端点直接计算. 考虑记录\(sum_x=\sum_{i=1}^x c_i\),设选\([l,r]\)时那个奇怪东西的 ...

  4. CodeForces 1107 - G Vasya and Maximum Profit 线段树

    题目传送门 题解: 枚举 r 的位置. 线段树每个叶子节点存的是对应的位置到当前位置的价值. 每次往右边移动一个r的话,那么改变的信息有2个信息: 1. sum(a-ci) 2.gap(l, r) 对 ...

  5. Maximum profit of stocks

    https://github.com/Premiumlab/Python-for-Algorithms--Data-Structures--and-Interviews/blob/master/Moc ...

  6. Yaoge’s maximum profit HDU - 5052

    Yaoge’s maximum profit Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/ ...

  7. Maximum Profit

    Maximum Profit You can obtain profits from foreign exchange margin transactions. For example, if you ...

  8. 【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 ...

  9. CodeForces 493B Vasya and Wrestling 【模拟】

    B. Vasya and Wrestling time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

随机推荐

  1. maven 聚合

    聚合很简单, 在父 pom 中写出子 pom 文件的路径即可 <name>parent Maven Webapp</name> <!-- FIXME change it ...

  2. 如何正确使用Espresso来测试你的Android程序

    UI测试在Android平台上一直都是一个令人头痛的事情, 由于大家平时用的很少, 加之很多文档的缺失, 如果很多东西从头摸索,势必踩坑无数. 自Android24正式淘汰掉了Instrumentat ...

  3. SpringBoot实现全文搜索

    • 全文搜索  • solr安装  • solr中文分词  • solr数据库导入  • solr数据查询  • solrj接口调用     1:

  4. MySQL自增列(AUTO_INCREMENT)相关知识点总结

      MySQL的自增列(AUTO_INCREMENT)和其它数据库的自增列对比,有很多特性和不同点(甚至不同存储引擎.不同版本也有一些不同的特性),让人感觉有点稍微复杂.下面我们从一些测试开始,来认识 ...

  5. mssql sqlserver text数据类型专题说明

    摘要: 下文分享text数据类型的简介及处理text数据类型所涉及的函数,如下所示: text 数据类型简介: mssql sqlserver 常用数据类型简介 mssql sqlserver tex ...

  6. SQLServer之修改标量值函数

    修改标量值函数注意事项 更改先前通过执行 CREATE FUNCTION 语句创建的现有 Transact-SQL 或 CLR 函数,但不更改权限,也不影响任何相关的函数.存储过程或触发器. 不能用 ...

  7. iOS开发者学习Flutter

    Flutter for iOS 开发者 本文档适用那些希望将现有 iOS 经验应用于 Flutter 的开发者.如果你拥有 iOS 开发基础,那么你可以使用这篇文档开始学习 Flutter 的开发. ...

  8. Android 系统版本和API level的关系表

    Android 系统版本和API level的关系表 wiki: https://zh.wikipedia.org/wiki/Android%E6%AD%B7%E5%8F%B2%E7%89%88%E6 ...

  9. oracle EM 如何调整界面显示的语言

    EM是通过浏览器语言来识别界面语言的,没有选项调整.我以chrome为例将默认中文改为英文: EM调整前为中文界面: 调整chrome语言显示为英文: 再重新开一个窗口,打开EM,界面已经调整为英文了 ...

  10. 【Linux基础】查看硬件信息-系统

    1.查看计算机名 hostname 2.查看内核/操作系统/CPU信息 uname -a   4.查看操作系统版本(Linux) head -n 2 /etc/issue Red Hat Enterp ...