当前位置:网站首页>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;
}
边栏推荐
- Special topic of binary tree -- acwing 3540 Binary search tree building (use the board to build a binary search tree and output the pre -, middle -, and post sequence traversal)
- TIPC Service and Topology Tracking4
- QT学习日记8——资源文件添加
- 【快应用】Win7系统使用华为IDE无法运行和调试项目
- [play with FPGA learning 2 in simple terms ----- design skills (basic grammar)]
- 洛谷 P5536 【XR-3】核心城市(贪心 + 树形 dp 寻找树的中心)
- Uncover the secrets of Huawei application market application statistics
- C#中索引器
- MySQL lethal serial question 4 -- are you familiar with MySQL logs?
- sql left join 主表限制条件写在on后面和写在where后面的区别
猜你喜欢
MongoDB 学习整理(条件操作符,$type 操作符,limit()方法,skip() 方法 和 sort() 方法)
【AI应用】海康威视iVMS-4200软件安装
二叉树专题--洛谷 P1229 遍历问题(乘法原理 已知前、后序遍历求中序遍历个数)
JVM garbage collector
How to implement tabbar title bar with list component
二叉树专题--AcWing 1589. 构建二叉搜索树
【AppLinking实战案例】通过AppLinking分享应用内图片
Special topic of binary tree -- Logu p1229 traversal problem (the number of traversals in the middle order is calculated when the pre and post order traversals of the multiplication principle are know
Hdu1234 door opener and door closer (water question)
What are the software product management systems? Inventory of 12 best product management tools
随机推荐
6种单例模式的实现方式
[AGC] how to solve the problem that the local display of event analysis data is inconsistent with that in AGC panel?
PCL projection point cloud
Uncover the secrets of Huawei application market application statistics
How to implement tabbar title bar with list component
flink二开,实现了个 batch lookup join(附源码)
点云投影图片
Implement custom drawer component in quick application
Creation and use of unified links in Huawei applinking
How to use ide to automatically sign and debug Hongmeng application
[quick application] win7 system cannot run and debug projects using Huawei ide
Mongodb learning and sorting (condition operator, $type operator, limit() method, skip() method and sort() method)
TIPC Cluster5
[ark UI] implementation of the startup page of harmonios ETS
函数式接口和方法引用
[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
OpenMLDB Meetup No.4 会议纪要
P1055 [noip2008 popularization group] ISBN number
洛谷 P4281 [AHOI2008]紧急集合 / 聚会(树上倍增 LCA)
Hdu1236 ranking (structure Sorting)