/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Wrong Answer 1ms 320.0 KiB
#2 Accepted 8ms 840.0 KiB
#3 Accepted 9ms 836.0 KiB
#4 Accepted 8ms 832.0 KiB
#5 Accepted 9ms 956.0 KiB
#6 Accepted 9ms 1.152 MiB
#7 Accepted 10ms 832.0 KiB
#8 Accepted 12ms 832.0 KiB
#9 Accepted 14ms 952.0 KiB
#10 Accepted 15ms 960.0 KiB
#11 Accepted 16ms 1.188 MiB
#12 Accepted 16ms 952.0 KiB
#13 Accepted 16ms 956.0 KiB
#14 Accepted 17ms 1.184 MiB
#15 Accepted 16ms 960.0 KiB
#16 Wrong Answer 16ms 836.0 KiB
#17 Wrong Answer 14ms 532.0 KiB
#18 Wrong Answer 13ms 532.0 KiB

Code


#include <bits/stdc++.h>

#ifdef LOCAL
#include "../algo/debug.h"
#else 
#define debug(...) 0
#endif

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int tt;
  cin >> tt;
  while (tt--) {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    sort(a.begin(), a.end());
    int m = k;
    for (int i = n - 1; i >= 0; i--) {
      while (i >= 0 && a[i] > m) {
        i--;
      }
      if (i < 0 || a[i] < m) {
        break;
      }
      m--;
    }
    if (m * 2 > a.back()) {
      cout << m << '\n';
      continue;
    }
    m = a.back() + 1;
    vector<long long> f(m);
    for (int i = 0; i < n; i++) {
      f[a[i]] += a[i];
    }
    long long ans = 1e18, w = 0;
    for (int i = 1; i <= k; i++) {
      long long now = 0;
      for (int j = i; j < m; j += i) {
        now += f[j];
      }
      if (now < ans) {
        ans = now;
        w = i;
      }
    }
    cout << w << '\n';
  }
  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 15:54:25
Judged At
2024-10-03 13:51:12
Judged By
Score
70
Total Time
17ms
Peak Memory
1.188 MiB