当前位置:网站首页>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;
}
边栏推荐
- AppGallery Connect场景化开发实战—图片存储分享
- php中self和static在方法中的区别
- TIPC messaging3
- 如何用list组件实现tabbar标题栏
- 洛谷 P4281 [AHOI2008]紧急集合 / 聚会(树上倍增 LCA)
- 三.芯片啟動和時鐘系統
- TIPC介绍1
- [AGC] how to solve the problem that the local display of event analysis data is inconsistent with that in AGC panel?
- Use of vscode tool
- [AI application] Hikvision ivms-4200 software installation
猜你喜欢

The first white paper on agile practice in Chinese enterprises was released | complete download is attached

TIPC Cluster5

二叉树专题--AcWing 1589. 构建二叉搜索树
![[AI application] Hikvision ivms-4200 software installation](/img/4e/1640e3cafac13ce4d39520195c3217.png)
[AI application] Hikvision ivms-4200 software installation

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
![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 19 The next node of the binary tree (find the successor of the node in the tree)

华为游戏初始化init失败,返回错误码907135000

2022爱分析· 国央企数字化厂商全景报告

The most detailed MySQL installation tutorial
随机推荐
static 函数中的静态变量
高德根据轨迹画线
php中self和static在方法中的区别
Jsp webshell Free from killing - The Foundation of JSP
Special topic of binary tree -- acwing 1589 Building binary search tree
js中给数组添加元素的方法有哪些
TIPC 寻址2
[play with FPGA learning 2 in simple terms ----- design skills (basic grammar)]
TIPC介绍1
PCL projection point cloud
QT学习日记7——QMainWindow
Special topic of binary tree -- [deep base 16. Example 7] ordinary binary tree (simplified version) (multiset seeks the precursor and subsequent sentry Art)
洛谷 P1892 [BOI2003]团伙(并查集变种 反集)
TIPC messaging3
二叉树专题--AcWing 47. 二叉树中和为某一值的路径(前序遍历)
Learn open62541 -- [66] UA_ Generation method of string
HDU1236 排名(结构体排序)
全网显示 IP 归属地,是怎么实现的?
[AGC] build service 3 - authentication service example
LabVIEW为什么浮点数会丢失精度