/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 11ms 788.0 KiB

Code

/*
Bismillahir Rahmanir Rahim
(In the name of Allah)

@Author Muhammad Nadim
*/

#include<bits/stdc++.h>
using namespace std;

#define     ll              long long
#define     ld              long double
#define     endl            '\n'
#define     pi              acos(-1.0)
#define     sp(n)           fixed<<setprecision(n)
#define     MNTDH_18        ios_base::sync_with_stdio(false); cin.tie(NULL);
#define     yes             cout<<"YES"<<"\n"
#define     no              cout<<"NO"<<"\n"
#define     debug(x, n)     for(ll i=0; i<n; i++)    cout<<x[i]<<" ";   //cout<<"\n"
#define     print(v)        for(auto &i: v) cout<<i<<" ";   cout<<"\n"
#define     all(v)          v.begin(), v.end()

template <typename T, typename U> T ceil(T x, U y) {return (x > 0 ? (x + y - 1) / y : x / y);}
template <typename T, typename U> T floor(T x, U y) {return (x > 0 ? x / y : (x - y + 1) / y);}

//typedef  __int128 lll;
typedef struct rafi
{
    ll type;
    ll idx1;
    ll idx2;
}R;

typedef struct sajeeb
{
    ll v1;
    ll v2;
}S;

typedef struct ohi
{
    ll l;
    ll r;
    ll u;
    ll d;
    int val;
}O;

const int N = 1e5+7, M=1e9+7, N1=21;
vector<int> d(N);

bool compare(S a, S b)
{
    if(a.v2<b.v2)   return 1;
    else if(a.v2==b.v2) return a.v1>b.v1;
    return 0;
}

void divCount()
{
    for(int i=1; i<N; i++)
    {
        for(int j=i; j<N; j+=i) d[j]++;
    }
}

void sF()
{
    ll n, k;
    cin>>n;

    ll a[n];
    for(int i=0; i<n; i++)  cin>>a[i];

    cin>>k;

    S b[n];
    for(int i=0; i<n; i++)
    {
        b[i].v1=a[i];
        b[i].v2=d[a[i]];
    }
    sort(b, b+n, compare);

    for(int i=0, j=0; i<n; i++, j++)
    {
        if(j==k-1)
        {
            cout<<b[i].v1<<endl;
            break;
        }
    }
    //for(int i=0; i<n; i++)  cout<<b[i].v1<<" ";
    //cout<<endl;
}

int main()
{
    MNTDH_18
    divCount();

    ll tc=1, cs=1;
    cin>>tc;
    
    while(tc--)
    {
        //cout<<"Case "<<cs++<<": ";
        sF();
    }

    return 0;
}

Information

Submit By
Type
Submission
Problem
P1008 Ordering Number
Language
C++17 (G++ 13.2.0)
Submit At
2023-12-08 04:03:55
Judged At
2024-11-11 03:49:13
Judged By
Score
100
Total Time
11ms
Peak Memory
788.0 KiB