当前位置:网站首页>The pain of Xiao Sha
The pain of Xiao Sha
2022-07-02 00:56:00 【Learning KL & TK】

Their thinking : You can use binary search , Found The current value adds up to the maximum value
#include"bits/stdc++.h"
#define ll long long
#define pi pair<int,int>
#define inf 0x3f3f3f3f
#define _for(i,a,b) for(int i=a;i<=b;i++)
#define for_(i,a,b) for(int i=a;i<b;i++)
#define _fr(i,a,b) for(int i=a;i>=b;i--)
#define fr_(i,a,b) for(int i=a;i>b;i--)
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
const int N = 1e6+5;
const ll mod = 1e9+7;
const double lp=1.000000011;
map<int,int>mp;
ll arr[N];
void solve(){
ll n,m,x;
cin >> n >> m;
_for(i,1,n) cin >> arr[i],arr[i]%=m;
sort(arr+1,arr+1+n);
ll res = (arr[n]+arr[n-1])%m;
_for(i,1,n){
x = lower_bound(arr+i+1,arr+n,m-arr[i])-arr;
if(x != i+1) res = max(res,(arr[i]+arr[x-1])%m);
}
cout << res << endl;
}
int main()
{
IOS;
solve();
return 0;
}边栏推荐
- Collection: comprehensive summary of storage knowledge
- PLC Analog input analog conversion FB s_ ITR (Mitsubishi FX3U)
- [CTF] bjdctf 2020 Bar _ Bacystack2
- cookie、session、tooken
- [cascade classifier training parameters] training Haar cascades
- @Valid参数校验不生效
- How do Lenovo computers connect Bluetooth headsets?
- Leetcode skimming: binary tree 03 (post order traversal of binary tree)
- @Valid parameter verification does not take effect
- 工作中非常重要的测试策略,你大概没注意过吧
猜你喜欢

Keepalived introduction and installation

What does open loop and closed loop mean?

【八大排序③】快速排序(动图演绎Hoare法、挖坑法、前后指针法)

excel数据透视表

Geek DIY open source solution sharing - digital amplitude frequency equalization power amplifier design (practical embedded electronic design works, comprehensive practice of software and hardware)

Leetcode skimming: binary tree 02 (middle order traversal of binary tree)

【微信授权登录】uniapp开发小程序,实现获取微信授权登录功能
![[eight sorts ①] insert sort (direct insert sort, Hill sort)](/img/8d/2c45a8fb582dabedcd2658cd7c54bc.png)
[eight sorts ①] insert sort (direct insert sort, Hill sort)

Leetcode skimming: stack and queue 03 (valid parentheses)

Zak's latest "neural information transmission", with slides and videos
随机推荐
UVM tutorial
[leetcode] number of maximum consecutive ones
Han Zhichao: real time risk control practice of eBay based on graph neural network
Bc35 & bc95 onenet mqtt (old)
Upgraded wechat tool applet source code for mobile phone detection - supports a variety of main traffic modes
cookie、session、tooken
Leetcode skimming: stack and queue 06 (top k high-frequency elements)
[conference resources] the Third International Conference on Automation Science and Engineering in 2022 (jcase 2022)
2023 Lexus ES products have been announced, which makes great progress this time
449 original code, complement code, inverse code
2022 safety officer-b certificate examination practice questions simulated examination platform operation
Node - generate wechat permission verification configuration
Global and Chinese market of wireless charging magnetic discs 2022-2028: Research Report on technology, participants, trends, market size and share
Creation of volume group for AIX storage management (I)
From 20s to 500ms, I used these three methods
Node -- egg creates a local file access interface
【CTF】bjdctf_2020_babystack2
Node——添加压缩文件
How to open an account for individual stock speculation? Is it safe?
Global and Chinese markets of beverage seasoning systems 2022-2028: Research Report on technology, participants, trends, market size and share