当前位置:网站首页>Xiao Sha's pain (thinking problem)
Xiao Sha's pain (thinking problem)
2022-06-30 15:01:00 【Rabbit doesn't like radish】
link :https://ac.nowcoder.com/acm/contest/27740/G
source : Cattle from

Correct code :
#include <bits/stdc++.h>
using namespace std;
const int N=1e6+10;
int a[N];
int n,p;
int main()
{
scanf("%d%d",&n,&p);
for(int i=0;i<n;i++)
{
scanf("%d",&a[i]);
a[i]=a[i]%p;
}
sort(a,a+n);
int maxn=(a[n-1]+a[n-2])%p;// After the above treatment ,a[i] Each number represented is less than p Number of numbers ,
// And the sum of the last two numbers (a[n-1]+a[n-2]) Again %p, Will be the remainder of the ceiling , No one is older than him
int l=0,r=n-1;
while(l<r)
{
if(a[l]+a[r]>=p)
r--;
else
{
maxn=max(maxn,a[l]+a[r]);
l++;
}
}
printf("%d\n",maxn);
return 0;
}
Error timeout code :
#include <bits/stdc++.h>
using namespace std;
const int N=1e6+10;
int a[N];
int n,p;
int main()
{
scanf("%d%d",&n,&p);
for(int i=0;i<n;i++)
{
cin>>a[i];
a[i]=a[i]%p;
}
sort(a,a+n);
long long minn=0;
for(int i=0;i<n;)
{
for(int j=n-1;j>i;)
{
long long mm=(long long)(a[i]+a[j])%p;
minn=max(minn,mm);
if(mm<p)
{
i++;
break;
}
else
{
j--;
}
}
}
printf("%lld\n",minn);
return 0;
}
边栏推荐
- JS to realize simple lottery function
- [matlab] 2D drawing summary
- Lihongyi machine learning 2020 homework summary
- 1076 forwards on Weibo (30 points)
- 1134: Legal C identifier query
- Win10 backup backup shows that creating a shared protection point on the shadow failed
- [extensive reading of papers] analyzing connections between user attributes, images, and text
- Programming exercises: special numbers (problem solving ideas + code implementation)
- Greedy two-dimensional array sorting
- Lost connection to the flow server (0 retries remaining): |Out of retries, exiting! Error reporting solution (flow)
猜你喜欢

Sum of CCF digits (full mark code + problem solving idea) 201512-1

How to get palindrome number in MATLAB (using fliplr function)

Shangpinhui knowledge points of large e-commerce projects

Determine the number of digits of an integer in MATLAB (one line of code)

2021-07-14 mybaitsplus

CCF call auction (full mark code + problem solving ideas + skill summary) 201412 - 3

CCF drawing (full mark code + problem solving ideas + skill summary) February 2, 2014

CCF Z-scan (full mark code + problem solving ideas) 201412-2
![[matlab] 2D drawing summary](/img/de/6bb5385f440a2997dbf9cbb9a756eb.jpg)
[matlab] 2D drawing summary
![[matlab] 3D drawing summary](/img/57/05156340ccdd79b866c4df955b3713.jpg)
[matlab] 3D drawing summary
随机推荐
Is pioneer futures safe? What are the procedures for opening futures accounts? How to reduce the futures commission?
[extensive reading of papers] multi modal sarcasm detection and human classification in code mixed conversations
How many questions can you answer for the interview of Mechanical Engineer?
高精度CNC加工中心为什么会出现误差?这4个原因你要注意!
JS array sorting method summary
Effect of shadow around the block after mouse over
CCF drawing (full mark code + problem solving ideas + skill summary) February 2, 2014
CCF elimination games (Full Score code + problem solving ideas + skill summary) February 2, 2015
Machine learning feature selection
Shift operator (detailed)
CCF sequence segmentation (Full Score code + problem solving idea) 201509 -1
PS cutting height 1px, Y-axis tiling background image problem
Why do high precision CNC machining centers have errors? You should pay attention to these four reasons!
1107 social clusters (30 points)
Invalid argument during startup: Failed to open the . conf file: redis-window
CCF window (Full Score code + problem solving idea) March 2, 2014
Sum of CCF digits (full mark code + problem solving idea) 201512-1
Analysis on the problems of irregular step hole on horizontal machining center
The difference between queue and stack
K high frequency elements before sorting