/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 764.0 KiB
#2 Accepted 17ms 536.0 KiB
#3 Accepted 17ms 532.0 KiB
#4 Accepted 15ms 532.0 KiB
#5 Accepted 17ms 540.0 KiB
#6 Accepted 17ms 544.0 KiB
#7 Accepted 18ms 492.0 KiB
#8 Accepted 22ms 544.0 KiB
#9 Accepted 28ms 604.0 KiB
#10 Accepted 46ms 1.129 MiB
#11 Accepted 75ms 2.52 MiB
#12 Accepted 78ms 2.406 MiB
#13 Accepted 73ms 2.449 MiB
#14 Accepted 106ms 2.512 MiB
#15 Accepted 131ms 2.516 MiB
#16 Accepted 112ms 2.52 MiB
#17 Accepted 548ms 2.383 MiB
#18 Accepted 3179ms 2.324 MiB

Code

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

int main(){
  int t;
  cin >> t;
  while (t--){
    ll n, a, x, cur = 0, ans = 1, mx = 0;
    cin >> n >> x;
    //vector<ll> a(n);
    map<ll, ll> mp;
    for (int i = 0; i < n; i++){
      cin >> a;
      cur += a;
      mp[a] += a;
      mx = max(mx, a);
    }
    for (int i = 2; i <= min(mx + 1, x); i++){
      ll cnt = 0;
      for (int j = i; j <= mx; j += i){
        cnt += mp[j];
      }
      if (cnt < cur){
        cur = cnt, ans = i;
        if (cur == 0) break;
      }
    }
    cout << ans << endl;
  }
}

Information

Submit By
Type
Submission
Problem
P1039 Prince Roy, the undisputed ruler of the world
Contest
Brain Booster #3
Language
C++17 (G++ 13.2.0)
Submit At
2024-05-06 17:51:57
Judged At
2024-10-03 13:47:51
Judged By
Score
100
Total Time
3179ms
Peak Memory
2.52 MiB