/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 328.0 KiB
#2 Accepted 30ms 532.0 KiB
#3 Accepted 30ms 512.0 KiB
#4 Accepted 28ms 532.0 KiB
#5 Accepted 30ms 540.0 KiB
#6 Accepted 32ms 540.0 KiB
#7 Accepted 32ms 392.0 KiB
#8 Accepted 39ms 536.0 KiB
#9 Accepted 48ms 600.0 KiB
#10 Accepted 74ms 1.133 MiB
#11 Accepted 118ms 2.516 MiB
#12 Accepted 126ms 2.508 MiB
#13 Accepted 96ms 2.5 MiB
#14 Accepted 132ms 2.516 MiB
#15 Accepted 153ms 2.523 MiB
#16 Accepted 144ms 2.668 MiB
#17 Accepted 554ms 2.391 MiB
#18 Accepted 3400ms 2.328 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-11-11 03:31:49
Judged By
Score
100
Total Time
3400ms
Peak Memory
2.668 MiB