QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#558453#5435. Clamped SequenceWuyanruWA 0ms3816kbC++141.6kb2024-09-11 16:13:582024-09-11 16:13:59

Judging History

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

  • [2024-09-11 16:13:59]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3816kb
  • [2024-09-11 16:13:58]
  • 提交

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]);

    ll ans=0;
    for(int i=1;i<=len;i++)
    {
        ll v=0;
        for(int j=i+1;j<=len;j++)
        {
            if(num[j]-num[i]>k) break;
            v+=(ll)(num[j]-num[j-1])*pre[j-1];
            int rest=k-num[j]+num[i];ans=max(ans,v);
            ans=max(ans,v+min(rest,num[i]-num[i-1])*pre[i-1]);
            ans=max(ans,v+min(rest,num[j+1]-num[j])*pre[j]);
        }
    }
    printf("%lld\n",ans);
    return 0;
}

詳細信息

Test #1:

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

input:

8 3
3 1 4 1 5 9 2 6

output:

15

result:

ok 1 number(s): "15"

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3764kb

input:

2 1
-1000000000 1000000000

output:

0

result:

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