当前位置:网站首页>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;
}
边栏推荐
- How does hbuilder display in columns?
- [extensive reading of papers] multimodal attribute extraction
- For loop and promise to solve the problem of concurrent callback
- Why do high precision CNC machining centers have errors? You should pay attention to these four reasons!
- Steps for commissioning of vertical machining center
- Computer screenshot how to cut the mouse in
- Implement a long-click list pop-up box on apiccloud
- val_ Loss decreases first and then increases or does not decrease but only increases
- PS cutting height 1px, Y-axis tiling background image problem
- Text matching - [naacl 2022] GPL
猜你喜欢

JS to realize simple lottery function

Component communication mode
![[matlab] 3D drawing summary](/img/57/05156340ccdd79b866c4df955b3713.jpg)
[matlab] 3D drawing summary

CCF elimination games (Full Score code + problem solving ideas + skill summary) February 2, 2015

ES6 notes
![[extensive reading of papers] multimodal attribute extraction](/img/ec/546c107ac0d31deded7ca94fdf0e2d.jpg)
[extensive reading of papers] multimodal attribute extraction

CCF string matching (Full Score code + problem solving ideas + skill summary) March 3, 2014

Error $(...) size is not a function

2021-07-14 mybaitsplus

Upgrade centos7 mysql5.5 to mysql5.7 non RPM in the form of tar package
随机推荐
1148 werewolf - Simple Version (20 points)
[matlab] 2D drawing summary
Bucket sorting (C language)
Shift operator (detailed)
立式加工中心的数控加工对刀具使用基本要求
数控加工中心打刀缸工作原理及故障处理
val_ Loss decreases first and then increases or does not decrease but only increases
分布式--OpenResty+lua+Redis
Hbuilder most commonly used and full shortcut key set
CCF drawing (full mark code + problem solving ideas + skill summary) February 2, 2014
2021-05-12
左旋梯形螺纹的编程
Distributed -- openresty+lua+redis
Not satisfied with markdown native code block style? Try this beautify code screenshot tool~~
K high frequency elements before sorting
1018 public bike Management (30 points)
[untitled]
CCF adjacent number pairs (Full Score code + problem solving ideas + skill summary) 201409-1
[extensive reading of papers] multimodal joint attribute prediction and value extraction for e-commerce product
How to use Alibaba Vector Icon