当前位置:网站首页>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】构建服务3-认证服务示例
QT learning diary 7 - qmainwindow
Overview of integrated learning
二叉树专题--AcWing 3540. 二叉搜索树建树(实用板子 构建二叉搜索树 并输出前、中、后序遍历)
Special topic of binary tree -- acwing 1497 Traversal of the tree (use post and mid order traversal to build a binary tree)
How to transfer event objects and user-defined parameters simultaneously in Huawei express applications
III Chip startup and clock system
快应用中实现自定义抽屉组件
三.芯片启动和时钟系统
Hdu1228 a + B (map mapping)
随机推荐
二叉树专题--AcWing 1497. 树的遍历(利用后、中序遍历,构建二叉树)
【ARK UI】HarmonyOS ETS的启动页的实现
Iii. Système de démarrage et d'horloge à puce
QT learning diary 8 - resource file addition
P1055 [noip2008 popularization group] ISBN number
Luogu p1892 [boi2003] Gang (and search for variant anti set)
Jsp webshell Free from killing - The Foundation of JSP
Logu p3398 hamster looks for sugar (double LCA on the tree to judge whether the two paths in the tree intersect)
Implement custom drawer component in quick application
III Chip startup and clock system
华为游戏初始化init失败,返回错误码907135000
static 函数中的静态变量
快应用中实现自定义抽屉组件
How does the whole network display IP ownership?
【AGC】如何解决事件分析数据本地和AGC面板中显示不一致的问题?
[play with FPGA learning 5 in simple terms ----- reset design]
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)
Appgallery connect scenario development practice - image storage and sharing
华为快应用中如何实现同时传递事件对象和自定义参数
Uncover the secrets of Huawei application market application statistics