QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#422754 | #6540. Beautiful Sequence | Bronya | WA | 0ms | 4088kb | C++20 | 771b | 2024-05-27 19:08:14 | 2024-05-27 19:08:15 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int n;
int a[300005];
inline int read(){
int x = 0, t = 1;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-')
t=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9'){
x=(x<<1)+(x<<3)+(ch^48);
ch=getchar();
}
return x*t;
}
void Solve(){
n=read();
for(int i=1;i<=n;i++)a[i]=read();
sort(a+1,a+1+n);
int hav=0,ans=0;
priority_queue<int>q;
for(int i=1;i<=n;i++){
int j=i;
while(j<n&&a[j+1]==a[i])j++;
ans+=j-i+1;
if(hav<0){
hav=-q.top();
q.pop();
}
if(hav)ans--;hav--;
q.push(-(j-i+1));
i=j;
}
printf("%d\n",ans);
}
int main(){
int T;
scanf("%d",&T);
while(T--)Solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3800kb
input:
2 6 1 1 2 3 3 4 5 1 2 2 3 3
output:
4 4
result:
ok 2 number(s): "4 4"
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 4088kb
input:
2 5 1 2 2 3 3 20 1 1 1 1 1 1 4 5 8 8 8 8 9 9 9 9 10 10 10 10
output:
4 15
result:
wrong answer 2nd numbers differ - expected: '17', found: '15'