题目分析:

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

代码:

 #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. 浅析 JavaScript 中的 函数 uncurrying 反柯里化

    柯里化 柯里化又称部分求值,其含义是给函数分步传递参数,每次传递参数后部分应用参数,并返回一个更具体的函数接受剩下的参数,这中间可嵌套多层这样的接受部分参数函数,直至返回最后结果. 因此柯里化的过程是 ...

  2. 使用ip开头的工具,而不是只会ifconfig

    结论: 1.使用ip 开头的工具,比ifconfig显示的信息更多,并且支持的功能更强大. 2.常用的功能有: 显示接口基本信息: ip link show dev eth0 设置端口up/down: ...

  3. ServiceHub.DataWarehouseHost.exe内存泄漏问题的处理

    Visual Studio 2017的15.2版本在debug应用程序时,ServiceHub.DataWarehouseHost.exe会出现严重的内存泄漏的问题,一个小时左右,内存耗了将近8GB. ...

  4. PSP总结报告

    此作业的要求参见[https://edu.cnblogs.com/campus/nenu/2018fall/homework/2556] 回顾0 alpha阶段前 团队名称:可以低头,但没必要 团队项 ...

  5. JAVA项目从运维部署到项目开发(三.Redis)

    一.Redis的介绍 Redis是一个开源的使用ANSI C语言编写.支持网络.可基于内存亦可持久化的日志型.Key-Value数据库,并提供多种语言的API.它通常被称为数据结构服务器,因为值(va ...

  6. 【公众号系列】SAP将裁员4400人,颤抖吧!

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[公众号系列]SAP将裁员4400人,颤抖吧! ...

  7. c/c++ 多线程 多个线程等待同一个线程的一次性事件

    多线程 多个线程等待一个线程的一次性事件 背景:从多个线程访问同一个std::future,也就是多个线程都在等待同一个线程的结果,这时怎么处理. 办法:由于std::future只能被调用一次get ...

  8. 【idea】Springboot整合jpa

    第一步快速搭建springboot项目:在你建立的工程下创建 Module 选择Spring initializr创建. 第二步:修改包名.项目名.web项目打成war包.在Type处选择: Mave ...

  9. centos7防火墙开放端口等命令

    CentOS 7 开放防火墙端口 命令 最近公司新的server要求用CentOS7, 发现以前CentOS 6 系列中的 iptables 相关命令不能用了,查了下,发现Centos 7使用fire ...

  10. pymsql模块

    老师的博客地址:http://www.cnblogs.com/wupeiqi/articles/5713330.html 通过pymysql 模块可以通过朋友去操作mysql 数据库,首先的在pip上 ...