当前位置:网站首页>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;
}
边栏推荐
- 二叉树专题--AcWing 1497. 树的遍历(利用后、中序遍历,构建二叉树)
- One trick to quickly realize custom application titlebar
- How to use ide to automatically sign and debug Hongmeng application
- 洛谷 P1892 [BOI2003]团伙(并查集变种 反集)
- Filtering of PCL
- [applinking practical case] share in app pictures through applinking
- Nodejs+express+mysql simple blog building
- MongoDB 学习整理(条件操作符,$type 操作符,limit()方法,skip() 方法 和 sort() 方法)
- Flick two open, realized a batch lookup join (with source code)
- 二叉树专题--洛谷 P1229 遍历问题(乘法原理 已知前、后序遍历求中序遍历个数)
猜你喜欢

Special topic of binary tree -- acwing 3384 Binary tree traversal (known preorder traversal, while building a tree, while outputting middle order traversal)

华为快应用中如何实现同时传递事件对象和自定义参数
![Binary tree topic -- Luogu p3884 [jloi2009] binary tree problem (DFS for binary tree depth BFS for binary tree width Dijkstra for shortest path)](/img/c2/bb85b681af0f78b380b1d179c7ea49.png)
Binary tree topic -- Luogu p3884 [jloi2009] binary tree problem (DFS for binary tree depth BFS for binary tree width Dijkstra for shortest path)

Special topic of binary tree -- acwing 18 Rebuild the binary tree (construct the binary tree by traversing the front and middle order)

What are the software product management systems? Inventory of 12 best product management tools

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

首份中国企业敏捷实践白皮书发布| 附完整下载

Huawei game failed to initialize init with error code 907135000

flink二開,實現了個 batch lookup join(附源碼)

Special topic of binary tree -- acwing 1497 Traversal of the tree (use post and mid order traversal to build a binary tree)
随机推荐
MTK full dump抓取
[in simple terms, play with FPGA learning 3 ----- basic grammar]
Special topic of binary tree -- acwing 47 Path with a certain value in binary tree (preorder traversal)
Creation and use of unified links in Huawei applinking
洛谷 P3398 仓鼠找 sugar(树上倍增 lca 判断树中两条路径是否相交 结论)
[play with FPGA learning 5 in simple terms ----- reset design]
Indexer in C #
PCL point cloud to depth image
Uncover the secrets of Huawei application market application statistics
函数式接口和方法引用
JVM之垃圾回收器
【深入浅出玩转FPGA学习4----漫谈状态机设计】
TIPC messaging3
【深入浅出玩转FPGA学习5-----复位设计】
快应用中实现自定义抽屉组件
MySQL lethal serial question 4 -- are you familiar with MySQL logs?
Why does LabVIEW lose precision in floating point numbers
二叉树专题--AcWing 18. 重建二叉树(利用前、中序遍历,构建二叉树)
Huawei game failed to initialize init with error code 907135000
Point cloud projection picture