题目分析:

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

代码:

 #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. EntityFramework实体默认值遇到Oracle自增主键

    1. Oracle实现主键自动增长 一般我们在Oracle实现主键自动增长,通常通过序列加触发器实现. 定义序列用于获取递增数字 CREATE SEQUENCE 序列名 [INCREMENT BY n ...

  2. Headless Android开发板的调试及远程显示和控制

    最近在调试msm8996的开发板,由于主板和LCD子板还没回来,所以先回的核心板算是个Headless的Android Device.核心板有独立供电,另外还有USB Type-C.FAN.HDMI. ...

  3. 南京邮电大学 JavaA期末复习要点总结

    南京邮电大学 JavaA复习要点: Chap1 入门 1.  Java应用程序开发过程教材P14~P15 Chap 2 基本语法 1.      标识符的命名规则教材P19 字母下划线美元符号开头,除 ...

  4. 珍藏版Chrome插件送给你们,不仅是程序员必备

    大家好,消失了几天我又满血复活归来了,最近这几天太忙了一直在加班工作,这不昨天又干到凌晨一点,今天早上七点就起来了,到现在还都没有休息,现在只剩半血了,不对应该说现在只能爬着走了,但是一想到几天没有更 ...

  5. ubuntu 通过apt安装jdk

    需要先添加ppa sudo add-apt-repository ppa:webupd8team/java sudo apt-get update 安装jdk8 sudo apt-get instal ...

  6. 【原】Java学习笔记014 - 面向对象

    package cn.temptation; public class Sample01 { public static void main(String[] args) { // 面向对象思想 // ...

  7. 文件比较命令(comp)

    comp命令: // 描述: 逐字节比较两个文件或文件集的内容. 如果在没有参数的情况下使用,comp会提示你输入要比较的文件. // 语法: comp [<Data1>] [<Da ...

  8. linux上修改mysql登陆密码

    1. 修改MySQL的登录设置: # vi /etc/my.cnf     2. 在[mysqld]的段中加上一句:skip-grant-tables  例如: [mysqld] port       ...

  9. linux磁盘IO读写性能优化

    在LINUX系统中,如果有大量读请求,默认的请求队列或许应付不过来,我们可以 动态调整请求队列数来提高效率,默认的请求队列数存放在/sys/block/xvda/queue/nr_requests 文 ...

  10. UVALive - 3713 - Astronauts(图论——2-SAT)

    Problem   UVALive - 3713 - Astronauts Time Limit: 3000 mSec Problem Description Input The input cont ...