QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#558444#5435. Clamped SequenceWuyanruWA 3ms3960kbC++141.5kb2024-09-11 16:10:482024-09-11 16:10:48

Judging History

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

  • [2024-09-11 16:10:48]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:3960kb
  • [2024-09-11 16:10:48]
  • 提交

answer

#include<bits/stdc++.h>
#define inf 0x3f3f3f3f3f3f3f3fll
#define debug(x) cerr<<#x<<"="<<x<<endl
using namespace std;
using ll=long long;
using ld=long double;
using pli=pair<ll,int>;
using pi=pair<int,int>;
template<typename A>
using vc=vector<A>;
inline int read()
{
    int s=0,w=1;char ch;
    while((ch=getchar())>'9'||ch<'0') if(ch=='-') w=-1;
    while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
    return s*w;
}
inline ll lread()
{
    ll s=0,w=1;char ch;
    while((ch=getchar())>'9'||ch<'0') if(ch=='-') w=-1;
    while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
    return s*w;
}
int pre[5005];
int num[5005];
int a[5005];
int n,k,len;
int main()
{
    n=read(),k=read();
    for(int i=1;i<=n;i++) num[i]=a[i]=read();
    sort(num+1,num+n+1),len=unique(num+1,num+n+1)-num-1;
    for(int i=1;i<=n;i++) a[i]=lower_bound(num+1,num+n+1,a[i])-num;
    for(int i=2;i<=n;i++) pre[min(a[i-1],a[i])]++,pre[max(a[i-1],a[i])]--;
    for(int i=1;i<=len;i++) pre[i]+=pre[i-1];

    // for(int i=1;i<=len;i++) printf("%d%c",num[i]," \n"[i==len]);
    // for(int i=1;i<=len;i++) printf("%d%c",pre[i]," \n"[i==len]);

    int now=1;ll ans=0;
    for(int i=1;i<=len;i++)
    {
        while(now<len&&num[now+1]-num[i]<=k) now++;
        ll v=0;int rest=k-num[now]+num[i];
        for(int j=i;j<now;j++) v+=(ll)(num[j+1]-num[j])*pre[j];
        ans=max(ans,v+(ll)rest*max(pre[i-1],pre[now]));
        // printf("i=%d now=%d ans=%lld  %lld,%d\n",i,now,ans,v,rest);
    }
    printf("%lld\n",ans);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 3820kb

input:

2 1
-1000000000 1000000000

output:

1

result:

ok 1 number(s): "1"

Test #3:

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

input:

2 1000000000
-1000000000 1000000000

output:

1000000000

result:

ok 1 number(s): "1000000000"

Test #4:

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

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: 3876kb

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: 3ms
memory: 3812kb

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:

7111099

result:

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