当前位置:网站首页>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;
}
边栏推荐
- 【深入浅出玩转FPGA学习4----漫谈状态机设计】
- Appgallery connect scenario development practice - image storage and sharing
- Jsp webshell Free from killing - The Foundation of JSP
- JSP webshell free -- the basis of JSP
- 金山云——2023届暑期实习
- 二叉树专题--洛谷 P1229 遍历问题(乘法原理 已知前、后序遍历求中序遍历个数)
- 一招快速实现自定义快应用titlebar
- 洛谷 P4281 [AHOI2008]紧急集合 / 聚会(树上倍增 LCA)
- STM32单片机编程学习
- 全网显示 IP 归属地,是怎么实现的?
猜你喜欢

Special topic of binary tree -- acwing 19 The next node of the binary tree (find the successor of the node in the tree)

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

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

二叉树专题--AcWing 18. 重建二叉树(利用前、中序遍历,构建二叉树)

Implement custom drawer component in quick application
![[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
![[in simple terms, play with FPGA learning 3 ----- basic grammar]](/img/f0/0204fa5197033877dc0758203253ae.png)
[in simple terms, play with FPGA learning 3 ----- basic grammar]

软件产品管理系统有哪些?12个最佳产品管理工具盘点

Common methods of JS array

Special topic of binary tree -- acwing 1497 Traversal of the tree (use post and mid order traversal to build a binary tree)
随机推荐
Openmldb meetup No.4 meeting minutes
Matlab processing of distance measurement of experimental electron microscope
Hdu1236 ranking (structure Sorting)
Hdu1228 a + B (map mapping)
Binary tree topic -- Luogu p3884 [jloi2009] binary tree problem (DFS for binary tree depth BFS for binary tree width Dijkstra for shortest path)
Resources读取2d纹理 转换为png格式
TIPC介绍1
TIPC协议
Calculate the sum of sequences
如何用list组件实现tabbar标题栏
P1055 [noip2008 popularization group] ISBN number
华为快应用中如何实现同时传递事件对象和自定义参数
flink二开,实现了个 batch lookup join(附源码)
高德根据轨迹画线
ImportError: cannot import name ‘Digraph‘ from ‘graphviz‘
Leetcode 182 Find duplicate email (2022.07.01)
【AGC】构建服务3-认证服务示例
如何使用IDE自动签名调试鸿蒙应用
Special topic of binary tree -- acwing 1497 Traversal of the tree (use post and mid order traversal to build a binary tree)
PCL projection point cloud