QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#559849#862. Social Justicerotcar07WA 3ms5532kbC++201.3kb2024-09-12 09:51:062024-09-12 09:51:08

Judging History

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

  • [2024-09-12 09:51:08]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:5532kb
  • [2024-09-12 09:51:06]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
constexpr int maxn=2e5+5;
int n;
typedef long long ll;
ll a[maxn],sum[maxn],p,q;
int id[maxn];
inline void solve(){
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i],id[i]=i;
    sort(id+1,id+n+1,[&](int x,int y){return a[x]<a[y];});
    sort(a+1,a+n+1);
    for(int i=1;i<=n;i++)sum[i]=sum[i-1]+a[i];
    cin>>p>>q;
    int mx=0,L=0,R=0;
    vector<pair<int,int>> sb;
    for(int i=1;i<=n;i++){
        int l=0,r=i-1;
        auto chk=[&](int d){
            return (sum[i]-sum[d])*p>=q*a[i]*(i-d);
        };
        while(l<r){
            int mid=l+r>>1;
            if(chk(mid)) r=mid;
            else l=mid+1;
        }
        if(i-r>mx){
            mx=i-r;L=r,R=i+1;
            sb.clear();
        }
        else if(i-r==mx){
            if(l>=R) sb.emplace_back(R,l);
            R=i+1;
        }
    }
    vector<int> v;
    for(auto [l,r]:sb) for(int i=l;i<=r;i++) v.push_back(id[i]);
    for(int i=1;i<=L;i++) v.push_back(id[i]);
    for(int i=R;i<=n;i++) v.push_back(id[i]);
    sort(v.begin(),v.end());
    cout<<v.size()<<'\n';
    for(auto x:v) cout<<x<<' ';cout<<'\n';
}
int main(){
    std::ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t;cin>>t;
    while(t--) solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5524kb

input:

3
4
1 2 3 4
3 2
5
1 15 2 5 1
2 1
5
1 2 3 1000 10000
4 3

output:

0

1
2 
2
4 5 

result:

ok 6 numbers

Test #2:

score: -100
Wrong Answer
time: 3ms
memory: 5532kb

input:

1000
1
10
3 2
2
10 100
3 2
3
10 10 100
3 2
4
1 2 3 4
3 2
5
1 15 2 5 1
2 1
5
1 2 3 1000 10000
4 3
6
1 2 3 4 1000 10000
4 3
5
50000 2 1 1 5000
2 1
10
1 15 2 5 1 10000 1 1 1 1
2 1
20
1 15 2 5 1 10000 1 1 1 1 1 15 2 5 1 10000 1 1 1 1
2 1
25
1 15 2 5 1 10000 1 1 1 1 1 15 2 5 1 10000 1 1 1 1 1 15 2 5 1
2 ...

output:

0

0

1
3 
0

1
2 
2
4 5 
3
1 5 6 
2
1 5 
3
2 4 6 
6
2 4 6 12 14 16 
8
2 4 6 12 14 16 22 24 
13
1 2 3 4 5 6 7 8 9 10 11 12 20 
15
1 2 3 4 5 6 7 8 9 10 11 12 18 19 20 
0

2
2 8 
2
9 12 
2
2 14 
10
1 4 5 6 7 13 14 15 18 20 
2
9 16 
2
16 18 
2
5 13 
10
4 5 6 9 11 15 16 18 19 20 
2
5 19 
2
5 13 
2
10 15...

result:

wrong answer 470th numbers differ - expected: '9', found: '10'