当前位置:网站首页>Xiao Sha's pain (double pointer
Xiao Sha's pain (double pointer
2022-07-02 11:11:00 【lcxdz】
#include<bits/stdc++.h>
using namespace std;
int n,p;
#define int long long
const int N=1e6+9;
int arr[N];
signed main(){
cin>>n>>p;
for(int i=1;i<=n;i++)scanf("%lld",&arr[i]),arr[i]%=p;
sort(arr+1,arr+1+n);
int mx=(arr[n-1]+arr[n])%p;// Note that there mx It is possible that the maximum value will not be obtained For example, when the data are all equal
for(int l=1,r=n;l<=n;l++){
while(r>0&&arr[r]+arr[l]>=p){
r--;
}
if(r>l)mx=max(mx,arr[r]+arr[l]);// The same array must r>l
}
cout<<mx<<endl;
return 0;
}
边栏推荐
- P1055 [noip2008 popularization group] ISBN number
- 二叉树专题--AcWing 1497. 树的遍历(利用后、中序遍历,构建二叉树)
- php中self和static在方法中的区别
- Overview of integrated learning
- Oracle 笔记
- 华为快应用中如何实现同时传递事件对象和自定义参数
- QT学习日记7——QMainWindow
- K-d tree and octree of PCL
- From Read and save in bag file Jpg pictures and PCD point cloud
- Special topic of binary tree -- acwing 3384 Binary tree traversal (known preorder traversal, while building a tree, while outputting middle order traversal)
猜你喜欢

如何用list组件实现tabbar标题栏

MTK full dump抓取

How to use ide to automatically sign and debug Hongmeng application

Matlab processing of distance measurement of experimental electron microscope

QT learning diary 8 - resource file addition

The most detailed MySQL installation tutorial

【深入浅出玩转FPGA学习5-----复位设计】

HDU1234 开门人和关门人(水题)

【快应用】text组件里的文字很多,旁边的div样式会被拉伸如何解决

【深入浅出玩转FPGA学习3-----基本语法】
随机推荐
Static variables in static function
洛谷 P4281 [AHOI2008]紧急集合 / 聚会(树上倍增 LCA)
从.bag文件中读取并保存.jpg图片和.pcd点云
2022 love analysis · panoramic report of digital manufacturers of state-owned enterprises
Openmldb meetup No.4 meeting minutes
最详细MySql安装教程
JSP webshell免殺——JSP的基礎
flink二開,實現了個 batch lookup join(附源碼)
AppGallery Connect场景化开发实战—图片存储分享
[quick application] there are many words in the text component. How to solve the problem that the div style next to it will be stretched
LabVIEW为什么浮点数会丢失精度
K-d tree and octree of PCL
二叉树专题--P1030 [NOIP2001 普及组] 求先序排列
static 函数中的静态变量
华为AppLinking中统一链接的创建和使用
Oracle 笔记
2022-06-17
[AI application] Hikvision ivms-4200 software installation
sqlite 修改列类型
OpenMLDB Meetup No.4 会议纪要