QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#401776#5435. Clamped Sequencexjt05WA 2ms3736kbC++23908b2024-04-29 12:47:592024-04-29 12:47:59

Judging History

你现在查看的是最新测评结果

  • [2024-04-29 12:47:59]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3736kb
  • [2024-04-29 12:47:59]
  • 提交

answer

#include<iostream>
#include<algorithm>
#include<math.h>
#include<string>
#include<string.h>
#include<queue>
#include<deque>
#include<vector>
#include<map>
#include<set>
#pragma GCC optimize(3,"Ofast","inline")
#define endl "\n"
using namespace std;
typedef long long ll;
ll n,m,a[5200],u=0;
ll check(ll x)
{
	ll ans=0,d=0,f=0,os=0;
	ll o=x+m;
	for(ll i=1;i<=n;i++)
	{
	if(a[i]>=x&&a[i]<=o)
	ans++;	
	if(a[i]<=x)
	d++;
	if(a[i]>=o)
	f++;
	if(i>=2)
	{
		ll z;
	if(a[i]<=x)
	z=x;
	else if(a[i]>=o)
	z=o;
	else z=a[i];
	ll r;
	if(a[i-1]<=x)
	r=x;
	else if(a[i-1]>=o)
	r=o;
	else r=a[i-1];
	os+=abs(r-z);
   }
	} 
	u=max(u,os);
	if(f>d)
	return 0;
	else
	return 1;
}
int main()
{
	cin>>n>>m;
for(ll i=1;i<=n;i++) cin>>a[i];
ll l=-1e9,r=1e9;
ll mid;
while(l<r)
{	
	mid=l+(r-l)/2;
	if(check(mid))
	{
		r=mid;
	}
	else
	l=mid+1;
}
cout<<u<<endl;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3580kb

input:

8 3
3 1 4 1 5 9 2 6

output:

15

result:

ok 1 number(s): "15"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3608kb

input:

2 1
-1000000000 1000000000

output:

1

result:

ok 1 number(s): "1"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3612kb

input:

2 1000000000
-1000000000 1000000000

output:

1000000000

result:

ok 1 number(s): "1000000000"

Test #4:

score: 0
Accepted
time: 2ms
memory: 3732kb

input:

5000 10000
-10000 10000 -10000 10000 -10000 10000 -10000 10000 -10000 10000 -10000 10000 -10000 10000 -10000 10000 -10000 10000 -10000 10000 -10000 10000 -10000 10000 -10000 10000 -10000 10000 -10000 10000 -10000 10000 -10000 10000 -10000 10000 -10000 10000 -10000 10000 -10000 10000 -10000 10000 -10...

output:

49990000

result:

ok 1 number(s): "49990000"

Test #5:

score: 0
Accepted
time: 1ms
memory: 3640kb

input:

5000 10000
10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 1...

output:

0

result:

ok 1 number(s): "0"

Test #6:

score: -100
Wrong Answer
time: 2ms
memory: 3736kb

input:

5000 2897
8987 9710 547 6523 -4484 8892 7360 7473 -5435 8122 -1396 -9963 -1884 -5758 -2930 2867 -260 -3947 -7915 -2428 4137 -1202 -1874 7205 -2852 -6126 -9346 -8662 2294 -4453 -2430 2424 9434 -112 2906 -169 -9489 -1977 68 -9072 2785 -2258 9710 271 8817 6251 3120 4765 -8449 -6625 2617 -3931 -4024 144...

output:

7109279

result:

wrong answer 1st numbers differ - expected: '7111087', found: '7109279'