QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#105563 | #4791. Movies | Determinant | WA | 2ms | 3752kb | C++14 | 610b | 2023-05-14 13:36:14 | 2023-05-14 13:36:16 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;const int N=1e5+7;
int n,m,ans=1e9,minn=1e9,fl=1,a[N],b[N],c[N];
int sum(int x){return a[c[x]]-x;}
int main(){
scanf("%d%d",&n,&m);
for(int i=1;i<=n;++i){scanf("%d",&a[i]);b[i]=a[i];if(a[i]>a[i-1])fl=0;}
if(fl){puts("0");return 0;}sort(b+1,b+n+1);
for(int i=1;i<=n;++i)c[lower_bound(b+1,b+n+1,a[i])-b]=i;
for(int r=1,l=1;r<n;++r){
if(c[r]<c[r-1])l=r;int x=max(2*(l-1)-1,2*(n-1-r));
if((m-sum(l)>=x-(x%2==0)&&sum(r)-sum(l)>=n-1-r-x%2)||
(sum(r)>=x-x%2&&sum(r)-sum(l)>=l-1-(x%2==0)))
ans=min(ans,x);
}
printf("%d\n",ans==1e9?-1:ans+1);
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 3752kb
input:
5 5 3 1 5 2 4 6 8 7 9 10
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 2ms
memory: 3572kb
input:
5 10 3 5 9 15 4 6 11 13 1 7 10 12 14 2 8
output:
4
result:
ok 1 number(s): "4"
Test #3:
score: 0
Accepted
time: 1ms
memory: 3508kb
input:
5 10 14 15 4 12 1 3 9 6 10 13 2 11 7 5 8
output:
3
result:
ok 1 number(s): "3"
Test #4:
score: 0
Accepted
time: 2ms
memory: 3544kb
input:
10 10 13 10 4 11 2 15 14 16 1 17 20 18 8 19 6 5 3 9 12 7
output:
-1
result:
ok 1 number(s): "-1"
Test #5:
score: 0
Accepted
time: 2ms
memory: 3712kb
input:
10 10 20 3 17 8 10 6 18 15 14 19 11 9 13 16 4 7 12 5 1 2
output:
9
result:
ok 1 number(s): "9"
Test #6:
score: 0
Accepted
time: 1ms
memory: 3576kb
input:
8 12 1 6 20 13 3 5 9 17 7 2 14 11 19 16 12 18 4 15 10 8
output:
6
result:
ok 1 number(s): "6"
Test #7:
score: 0
Accepted
time: 2ms
memory: 3576kb
input:
10 10 9 6 16 10 18 5 20 17 13 1 14 8 19 2 12 11 3 7 4 15
output:
7
result:
ok 1 number(s): "7"
Test #8:
score: -100
Wrong Answer
time: 2ms
memory: 3600kb
input:
10 10 7 2 19 5 20 4 14 15 9 16 17 8 12 11 13 10 1 3 6 18
output:
-1
result:
wrong answer 1st numbers differ - expected: '9', found: '-1'