当前位置:网站首页>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;
}
边栏推荐
- [AGC] build service 3 - authentication service example
- TIPC Service and Topology Tracking4
- Hdu1234 door opener and door closer (water question)
- Special topic of binary tree -- acwing 1589 Building binary search tree
- Special topic of binary tree -- acwing 47 Path with a certain value in binary tree (preorder traversal)
- Special topic of binary tree -- acwing 19 The next node of the binary tree (find the successor of the node in the tree)
- 全网显示 IP 归属地,是怎么实现的?
- HDU1228 A + B(map映射)
- Special topic of binary tree -- acwing 18 Rebuild the binary tree (construct the binary tree by traversing the front and middle order)
- Static variables in static function
猜你喜欢

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

TIPC Service and Topology Tracking4

Creation and use of unified links in Huawei applinking

MTK full dump抓取
![二叉树专题--洛谷 P3884 [JLOI2009]二叉树问题(dfs求二叉树深度 bfs求二叉树宽度 dijkstra求最短路)](/img/c2/bb85b681af0f78b380b1d179c7ea49.png)
二叉树专题--洛谷 P3884 [JLOI2009]二叉树问题(dfs求二叉树深度 bfs求二叉树宽度 dijkstra求最短路)

TIPC messaging3
![[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](/img/5c/b0030fd5fbc07eb94013f2699c2a04.png)
[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

Flick two open, realized a batch lookup join (with source code)

Mongodb learning and sorting (condition operator, $type operator, limit() method, skip() method and sort() method)

flink二开,实现了个 batch lookup join(附源码)
随机推荐
js中给数组添加元素的方法有哪些
Filtering of PCL
The first white paper on agile practice in Chinese enterprises was released | complete download is attached
Openmldb meetup No.4 meeting minutes
【AppLinking实战案例】通过AppLinking分享应用内图片
AppGallery Connect场景化开发实战—图片存储分享
Luogu p1892 [boi2003] Gang (and search for variant anti set)
Flick two open, realized a batch lookup join (with source code)
Special topic of binary tree -- acwing 1497 Traversal of the tree (use post and mid order traversal to build a binary tree)
Oracle 笔记
软件产品管理系统有哪些?12个最佳产品管理工具盘点
TIPC Service and Topology Tracking4
二.Stm32f407芯片GPIO编程,寄存器操作,库函数操作和位段操作
sqlite 修改列类型
JVM garbage collector
TIPC Getting Started6
MySQL lethal serial question 4 -- are you familiar with MySQL logs?
[applinking practical case] share in app pictures through applinking
二叉树专题--AcWing 19. 二叉树的下一个节点(找树中节点的后继)
Special topic of binary tree -- acwing 18 Rebuild the binary tree (construct the binary tree by traversing the front and middle order)