题目链接: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天呆在那得到的拥抱值最大

如果选取的这段日期至少覆盖到两个月份。如果右端点不是月末的话,假设左端点对应的日期大于右端点对应的日期,那么整体往左移动区间就能使得答案增加;同理假设左端点对应的日期小于右端点对应的日期可以整体往右移动。最后都会使得右端点靠到某个月的月末。

代码:

  1. #include<stdio.h>
  2. #include<algorithm>
  3. #include<iostream>
  4. #include<string>
  5. #include<queue>
  6. #include<deque>
  7. #include<string.h>
  8. #include<map>
  9. #include <iostream>
  10. #include <math.h>
  11. #define Mem(a,b) memset(a,b,sizeof(a))
  12. const double II = acos(-1);
  13. const double PP = (II*1.0)/(180.00);
  14. using namespace std;
  15. typedef long long ll;
  16. const int INF=0x3f3f3f3f;
  17. const double eps=1e-6;
  18. const double PI=acos(-1);
  19. const int mod=998244353;
  20. const int maxn=2e5+10;
  21. long long d[400005];
  22. long long sum[400005];
  23. long long ssum[400005];
  24. long long ans=0;
  25. long long n,x;//xһ��Ҫ��long long ��Ϊ��d�ĺ�
  26. int check(long long mid,long long k)
  27. {
  28. if(sum[k]-sum[mid]>=x) return 0;
  29. else
  30. {
  31. if(sum[k]-sum[mid-1]>=x) return 1;
  32. else return 2;
  33. }
  34. }
  35. int main()
  36. {
  37. cin>>n>>x;
  38. int i;
  39. for(i=1;i<=n;i++)
  40. {
  41. scanf("%lld",&d[i]);
  42. d[i+n]=d[i];
  43. }
  44. for(i=1;i<=2*n;i++)
  45. {
  46. sum[i]=sum[i-1]+d[i];
  47. ssum[i]=ssum[i-1]+(1+d[i])*d[i]/2;
  48. }
  49. for(i=n+1;i<=2*n;i++)
  50. {
  51. long long l=1,r=i,mid,pos;
  52. while(1)
  53. {
  54. mid=(l+r)/2;
  55. int judge=check(mid,i);
  56. if(judge==2) r=mid;
  57. else if(judge==0) l=mid+1;
  58. else
  59. {
  60. pos=mid;
  61. break;
  62. }
  63. }
  64. if(pos==i)//��ͬһ����
  65. {
  66. ans=max(ans,x*d[i]-(long long)x*(x-1)/2*1);
  67. }
  68. else
  69. {
  70. long long temp=ssum[i]-ssum[pos];
  71. long long xx=x-(sum[i]-sum[pos]);
  72. temp+=xx*d[pos]-xx*(xx-1)/2;
  73. ans=max(ans,temp);
  74. }
  75.  
  76. }
  77. cout<<ans<<endl;
  78. return 0;
  79. }

Codeforces Round #645 (Div. 2) D、The Best Vacation的更多相关文章

  1. Codeforces Round #437 (Div. 2)[A、B、C、E]

    Codeforces Round #437 (Div. 2) codeforces 867 A. Between the Offices(水) 题意:已知白天所在地(晚上可能坐飞机飞往异地),问是否从 ...

  2. 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 ...

  3. 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时,此路不通.路 ...

  4. Codeforces Round #604 (Div. 2) D、E、F题解

    Beautiful Sequence Beautiful Mirrors Beautiful Bracket Sequence (easy version) Beautiful Sequence \[ ...

  5. Codeforces Round #674 (Div. 3) C、D 题解

    C.Increase and Copy #枚举 题目链接 题意 最初你有仅包含一个数字\(1\)的数组\(a\),一次操作中可对该数组进行两类操作: 从数组中选择一个元素,将该元素\(+1\): 从数 ...

  6. Codeforces Round #677 (Div. 3) E、G题解

    E. Two Round Dances #圆排列 题目链接 题意 \(n\)(保证偶数)个人,要表演一个节目,这个节目包含两种圆形舞蹈,而每种圆形舞蹈恰好需要\(n/2\)个人,每个人只能跳一种圆形舞 ...

  7. Codeforces Round #667 (Div. 3) B、C、D、E 题解

    抱歉B.C题咕了这么久 B. Minimum Product #枚举 #贪心 题目链接 题意 给定四个整数\(a, b, x, y\),其中\(a\geq x, b\geq y\),你可以执行不超过\ ...

  8. Codeforces Round #660 (Div. 2) A、B、C题解

    A. Captain Flint and Crew Recruitment #构造 题目链接 题意 定义一类正整数,能够被\(p*q\)表示,其中\(p.q(1<p<q)\)均为素数,称之 ...

  9. 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 ...

随机推荐

  1. 【Java基础】数组和算法

    数组和算法 查找算法 线性查找 ... 二分查找 二分查找要求数据结构是有序的. package com.parzulpan.java.ch03; /** * @Author : parzulpan ...

  2. 【C++】《Effective C++》第六章

    第六章 继承与面向对象设计 条款32:确定你的public继承塑模出is-a关系 public隐含的寓意:每个派生类对象同时也是一个基类对象,反之不成立.只不过基类比派生类表现出更一般化的概念,派生类 ...

  3. 在CentOS上安装Singularity高性能容器

    什么是singularity容器 Singularity是劳伦斯伯克利国家实验室专门为大规模.跨节点HPC和DL工作负载而开发的容器化技术.具备轻量级.快速部署.方便迁移等诸多优势,且支持从Docke ...

  4. python学习笔记 | selenium各浏览器驱动下载地址

    Chrome http://chromedriver.storage.googleapis.com/index.html 不同的Chrome的版本对应的chromedriver.exe 版本也不一样, ...

  5. 我们NetCore下日志存储设计

    日志的分类 首先往大的来说,日志分2种 ①业务日志: 即业务系统需要查看的日志, 常见的比如谁什么时候修改了什么. ②参数日志: 一般是开发人员遇到问题的时候定位用的, 一般不需要再业务系统里展示. ...

  6. (十八)configparser模块

    configparser模块一般是用来处理配置文件的,如: [DEFAULT] ServerAliveInterval = 45 Compression = yes CompressionLevel ...

  7. 【Linux】系统打开文件最大数量限制(进程打开的最大文件句柄数设置)

    利用ulimit命令可以对资源的可用性进行控制. -H选项和-S选项分别表示对给定资源的硬限制(hard limit)和软限制(soft limit)进行设置. 硬限制(hard limit)一旦被设 ...

  8. 【Oracle】删除表空间

    删除表空间如果是 SQL> DROP TABLEPSACE XXXX; 是无法将数据文件一同都删除的 想要删除表空间和数据文件需要如下操作: SQL> drop tablespace XX ...

  9. 【ORA】ORA-32004: 问题分析和解决

    今天做一个特殊的实验,需要重启数据库 数据库关闭没有问题 SQL> shutdown immediate; Database closed. Database dismounted. ORACL ...

  10. CTFHub - Web(三)

    密码口令: 弱口令: 1.随意输入账号密码,抓包, 2.右击,"Send to Intruder",打开选项卡Intruder,点击position,椭圆框处软件已经自动为我们把要 ...