/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 14ms 4.359 MiB
#2 Accepted 17ms 4.367 MiB
#3 Accepted 18ms 4.367 MiB
#4 Accepted 18ms 4.363 MiB
#5 Accepted 16ms 4.363 MiB
#6 Accepted 18ms 4.371 MiB
#7 Accepted 21ms 4.363 MiB
#8 Accepted 29ms 4.359 MiB
#9 Accepted 31ms 4.363 MiB
#10 Accepted 31ms 4.363 MiB
#11 Accepted 32ms 4.258 MiB
#12 Accepted 33ms 4.363 MiB
#13 Accepted 25ms 4.371 MiB
#14 Accepted 41ms 4.367 MiB
#15 Accepted 48ms 4.371 MiB
#16 Accepted 56ms 4.359 MiB
#17 Accepted 343ms 4.371 MiB
#18 Accepted 3281ms 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-11-11 03:33:15
Judged By
Score
100
Total Time
3281ms
Peak Memory
4.371 MiB