当前位置:网站首页>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;
}
边栏推荐
- The difference between self and static in PHP in methods
- php中self和static在方法中的区别
- Filtering of PCL
- Why does LabVIEW lose precision in floating point numbers
- 【深入浅出玩转FPGA学习2----设计技巧(基本语法)】
- [applinking practical case] share in app pictures through applinking
- Regular and common formulas
- QT learning diary 7 - qmainwindow
- TIPC messaging3
- From Read and save in bag file Jpg pictures and PCD point cloud
猜你喜欢

Openmldb meetup No.4 meeting minutes

华为应用市场应用统计数据问题大揭秘

Hdu1234 door opener and door closer (water question)

Implement custom drawer component in quick application

TIPC Service and Topology Tracking4
![[play with FPGA learning 5 in simple terms ----- reset design]](/img/57/816a59787259dc32b52897c069e1a6.png)
[play with FPGA learning 5 in simple terms ----- reset design]

二叉树专题--AcWing 3384. 二叉树遍历(已知先序遍历 边建树 边输出中序遍历)

Special topic of binary tree -- acwing 47 Path with a certain value in binary tree (preorder traversal)

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
随机推荐
金山云——2023届暑期实习
【付费推广】常见问题合集,推荐榜单FAQ
全网显示 IP 归属地,是怎么实现的?
Special topic of binary tree -- acwing 3384 Binary tree traversal (known preorder traversal, while building a tree, while outputting middle order traversal)
P1055 [NOIP2008 普及组] ISBN 号码
洛谷 P3398 仓鼠找 sugar(树上倍增 lca 判断树中两条路径是否相交 结论)
【AGC】构建服务3-认证服务示例
Appgallery connect scenario development practice - image storage and sharing
Primary key policy problem
PCL projection point cloud
[play with FPGA learning 4 in simple terms ----- talk about state machine design]
The difference between self and static in PHP in methods
二叉树专题--P1030 [NOIP2001 普及组] 求先序排列
二叉树专题--洛谷 P3884 [JLOI2009]二叉树问题(dfs求二叉树深度 bfs求二叉树宽度 dijkstra求最短路)
Jsp webshell Free from killing - The Foundation of JSP
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 1497 Traversal of the tree (use post and mid order traversal to build a binary tree)
AppGallery Connect场景化开发实战—图片存储分享
点云投影图片
C# 文件与文件夹操作