/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 12ms 4.27 MiB
#2 Accepted 11ms 4.367 MiB
#3 Accepted 12ms 4.363 MiB
#4 Accepted 12ms 4.316 MiB
#5 Accepted 12ms 4.398 MiB
#6 Accepted 13ms 4.23 MiB
#7 Accepted 14ms 4.312 MiB
#8 Accepted 23ms 4.312 MiB
#9 Accepted 24ms 4.359 MiB
#10 Accepted 23ms 4.27 MiB
#11 Accepted 25ms 4.316 MiB
#12 Accepted 24ms 4.25 MiB
#13 Accepted 17ms 4.27 MiB
#14 Accepted 38ms 4.367 MiB
#15 Accepted 40ms 4.367 MiB
#16 Accepted 47ms 4.363 MiB
#17 Accepted 300ms 4.363 MiB
#18 Accepted 2807ms 4.367 MiB

Code

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

#define ll unsigned long long
#define endl '\n'
const int N = 1e6+4;

void solve(int cs){
    int n,x;
    cin>>n>>x;
    int cnt[N] = {0};
    ll s = 0;
    for(int i = 0; i < n; i++){
        int a;cin>>a;
        cnt[a]++;
        s += a;
    }
    int ans = 1;
    
    for(int i = 1; i <= x; i++){
        ll tm = 0;
        for(int j = i; j < N; j+=i){
            tm += (j*1ll*cnt[j]);
        }
        if(tm < s){
            ans = i;
            s = tm;
        }
    }
    cout<<ans<<endl;
}
   
int main()
{

    ios_base::sync_with_stdio(false);cin.tie(0);
    int t=1,cs=0;
    cin >> t;
    while(t--)
    {
        solve(++cs);
    }

    return 0;
}

Information

Submit By
Type
Submission
Problem
P1039 Prince Roy, the undisputed ruler of the world
Contest
Brain Booster #3
Language
C++20 (G++ 13.2.0)
Submit At
2024-05-06 16:19:05
Judged At
2024-10-03 13:50:32
Judged By
Score
100
Total Time
2807ms
Peak Memory
4.398 MiB