Codeforces Round #645 (Div. 2) D、The Best Vacation
题目链接:The Best Vacation
题意:
给你n个月份,每一个月份有di天。你可以呆在那里x天(x天要连续),如果你在某月的第y天呆在这。那么你的拥抱值就加y
1<=n<=2e5
1<=di<=1e6
题解:
首先这段日期的结尾一定是月末。下面证明
如果x<=max(d1,d2...dn)
那么肯定是在那个max(d1,d2...dn)那个月最后x天呆在那得到的拥抱值最大
如果选取的这段日期至少覆盖到两个月份。如果右端点不是月末的话,假设左端点对应的日期大于右端点对应的日期,那么整体往左移动区间就能使得答案增加;同理假设左端点对应的日期小于右端点对应的日期可以整体往右移动。最后都会使得右端点靠到某个月的月末。
代码:
- #include<stdio.h>
- #include<algorithm>
- #include<iostream>
- #include<string>
- #include<queue>
- #include<deque>
- #include<string.h>
- #include<map>
- #include <iostream>
- #include <math.h>
- #define Mem(a,b) memset(a,b,sizeof(a))
- const double II = acos(-1);
- const double PP = (II*1.0)/(180.00);
- using namespace std;
- typedef long long ll;
- const int INF=0x3f3f3f3f;
- const double eps=1e-6;
- const double PI=acos(-1);
- const int mod=998244353;
- const int maxn=2e5+10;
- long long d[400005];
- long long sum[400005];
- long long ssum[400005];
- long long ans=0;
- long long n,x;//xһ��Ҫ��long long ��Ϊ��d�ĺ�
- int check(long long mid,long long k)
- {
- if(sum[k]-sum[mid]>=x) return 0;
- else
- {
- if(sum[k]-sum[mid-1]>=x) return 1;
- else return 2;
- }
- }
- int main()
- {
- cin>>n>>x;
- int i;
- for(i=1;i<=n;i++)
- {
- scanf("%lld",&d[i]);
- d[i+n]=d[i];
- }
- for(i=1;i<=2*n;i++)
- {
- sum[i]=sum[i-1]+d[i];
- ssum[i]=ssum[i-1]+(1+d[i])*d[i]/2;
- }
- for(i=n+1;i<=2*n;i++)
- {
- long long l=1,r=i,mid,pos;
- while(1)
- {
- mid=(l+r)/2;
- int judge=check(mid,i);
- if(judge==2) r=mid;
- else if(judge==0) l=mid+1;
- else
- {
- pos=mid;
- break;
- }
- }
- if(pos==i)//��ͬһ����
- {
- ans=max(ans,x*d[i]-(long long)x*(x-1)/2*1);
- }
- else
- {
- long long temp=ssum[i]-ssum[pos];
- long long xx=x-(sum[i]-sum[pos]);
- temp+=xx*d[pos]-xx*(xx-1)/2;
- ans=max(ans,temp);
- }
- }
- cout<<ans<<endl;
- return 0;
- }
Codeforces Round #645 (Div. 2) D、The Best Vacation的更多相关文章
- Codeforces Round #437 (Div. 2)[A、B、C、E]
Codeforces Round #437 (Div. 2) codeforces 867 A. Between the Offices(水) 题意:已知白天所在地(晚上可能坐飞机飞往异地),问是否从 ...
- Codeforces Round #298 (Div. 2) A、B、C题
题目链接:Codeforces Round #298 (Div. 2) A. Exam An exam for n students will take place in a long and nar ...
- Codeforces Round #482 (Div. 2) C 、 Kuro and Walking Route(dfs)979C
题目链接:http://codeforces.com/contest/979/problem/C 大致题意 给出n个点,有n-1个边将他们链接.给出x,y,当某一路径中出现x....y时,此路不通.路 ...
- Codeforces Round #604 (Div. 2) D、E、F题解
Beautiful Sequence Beautiful Mirrors Beautiful Bracket Sequence (easy version) Beautiful Sequence \[ ...
- Codeforces Round #674 (Div. 3) C、D 题解
C.Increase and Copy #枚举 题目链接 题意 最初你有仅包含一个数字\(1\)的数组\(a\),一次操作中可对该数组进行两类操作: 从数组中选择一个元素,将该元素\(+1\): 从数 ...
- Codeforces Round #677 (Div. 3) E、G题解
E. Two Round Dances #圆排列 题目链接 题意 \(n\)(保证偶数)个人,要表演一个节目,这个节目包含两种圆形舞蹈,而每种圆形舞蹈恰好需要\(n/2\)个人,每个人只能跳一种圆形舞 ...
- Codeforces Round #667 (Div. 3) B、C、D、E 题解
抱歉B.C题咕了这么久 B. Minimum Product #枚举 #贪心 题目链接 题意 给定四个整数\(a, b, x, y\),其中\(a\geq x, b\geq y\),你可以执行不超过\ ...
- Codeforces Round #660 (Div. 2) A、B、C题解
A. Captain Flint and Crew Recruitment #构造 题目链接 题意 定义一类正整数,能够被\(p*q\)表示,其中\(p.q(1<p<q)\)均为素数,称之 ...
- Codeforces Round #676 (Div. 2) XORwice、Putting Bricks in the Wall、Palindromifier
题目链接:XORwice 题意:给你两个数a.b.求一个数x,使得((a异或x)+(b异或x))这个值最小,输出最小那个x 题解: 输出(a|b)-(a&b)就行(猜了一手 代码: #incl ...
随机推荐
- 【Java基础】数组和算法
数组和算法 查找算法 线性查找 ... 二分查找 二分查找要求数据结构是有序的. package com.parzulpan.java.ch03; /** * @Author : parzulpan ...
- 【C++】《Effective C++》第六章
第六章 继承与面向对象设计 条款32:确定你的public继承塑模出is-a关系 public隐含的寓意:每个派生类对象同时也是一个基类对象,反之不成立.只不过基类比派生类表现出更一般化的概念,派生类 ...
- 在CentOS上安装Singularity高性能容器
什么是singularity容器 Singularity是劳伦斯伯克利国家实验室专门为大规模.跨节点HPC和DL工作负载而开发的容器化技术.具备轻量级.快速部署.方便迁移等诸多优势,且支持从Docke ...
- python学习笔记 | selenium各浏览器驱动下载地址
Chrome http://chromedriver.storage.googleapis.com/index.html 不同的Chrome的版本对应的chromedriver.exe 版本也不一样, ...
- 我们NetCore下日志存储设计
日志的分类 首先往大的来说,日志分2种 ①业务日志: 即业务系统需要查看的日志, 常见的比如谁什么时候修改了什么. ②参数日志: 一般是开发人员遇到问题的时候定位用的, 一般不需要再业务系统里展示. ...
- (十八)configparser模块
configparser模块一般是用来处理配置文件的,如: [DEFAULT] ServerAliveInterval = 45 Compression = yes CompressionLevel ...
- 【Linux】系统打开文件最大数量限制(进程打开的最大文件句柄数设置)
利用ulimit命令可以对资源的可用性进行控制. -H选项和-S选项分别表示对给定资源的硬限制(hard limit)和软限制(soft limit)进行设置. 硬限制(hard limit)一旦被设 ...
- 【Oracle】删除表空间
删除表空间如果是 SQL> DROP TABLEPSACE XXXX; 是无法将数据文件一同都删除的 想要删除表空间和数据文件需要如下操作: SQL> drop tablespace XX ...
- 【ORA】ORA-32004: 问题分析和解决
今天做一个特殊的实验,需要重启数据库 数据库关闭没有问题 SQL> shutdown immediate; Database closed. Database dismounted. ORACL ...
- CTFHub - Web(三)
密码口令: 弱口令: 1.随意输入账号密码,抓包, 2.右击,"Send to Intruder",打开选项卡Intruder,点击position,椭圆框处软件已经自动为我们把要 ...