提出 #65509762


ソースコード 拡げる

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

typedef long long ll;
typedef pair<int, int> pii;
constexpr int MAXN = 1'000'007;
constexpr int INF = 2'000'000'000;
constexpr ll INFF = 1'000'000'000'000'000'000LL;
constexpr ll MOD = 998'244'353;
#define mkp make_pair
#define F first
#define S second
#define pb emplace_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()

int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> a(n);
    vector<ll> p(n);
    for (auto &i : a)
      cin >> i;
    sort(all(a));
    if (a[0] == a[n - 1]) {
      cout << 0 << '\n';
      continue;
    }
    int L = 1, R = n;
    while (R - L > 1) {
      int M = (L + R) >> 1;
      ll sum = 0;
      bool ok = 0;
      for (int i = 0; i < n; i++) {
        sum += a[i];
        if (i < M - 1)
          continue;
        if (sum < a[i - M + 1] * 1LL * (i + 1))
          ok = 1;
      }
      if (ok)
        L = M;
      else
        R = M;
    }
    cout << L << '\n';
  }
}
/*
- How to come up with solutions? (https://hackmd.io/-3cIVAFSQMC3iJTh9EpszA)
  - Play with some small examples.
  - Make observations (or random guesses) by intuition.
    - Try to find counterexamples of the "observations."
  - Find the characteristics of an optimal solution.
  - Try to solve simple cases.
  - Brute force and print out the results.
  - Pick a method (greedy, dp, d&c, ...)
    - But DO NOT force algos on problems!
  - IF YOU'RE STUCK, TRY SOMETHING ELSE! Make new observations!

- Before writing the solution:
  - check TL/ML/correctness of samples/implementation details!

- Pre-submit:
  - Did you make a typo when copying a template?
  - Test more cases if unsure.
    - Write a naive solution and check small cases.
  - Submit the correct file.

- Debugging:
  - General Debugging:
    - Read the whole problem again.
    - Think over the algorithm again.
    - Go to the toilet.

  - Wrong Answer:
    - Any possible overflows?
      - > `__int128` ?
      - Try `-ftrapv` or `#pragma GCC optimize("trapv")`
    - Floating point errors?
      - > `long double` ?
      - turn off math optimizations
      - check for `==`, `>=`, `acos(1.000000001)`, etc.
    - Did you forget to sort or unique?
    - Generate large and worst "corner" cases.
    - Check your `m` / `n`, `i` / `j`,  `x` / `y` and `<` / `>`.
    - Are everything initialized or reset properly?
    - Are you sure about the STL thing you are using?
      - Read cppreference.
    - Print everything and run it on pen and paper.

  - Time Limit Exceeded:
    - Calculate your time complexity again.
    - Does the program actually end?
      - Check for `while(q.size())` etc.
    - Test the largest cases locally.
    - Did you do unnecessary stuff?
      - e.g. pass vectors by value
      - e.g. `memset` for every test case
    - Is your constant factor reasonable?

  - Runtime Error:
    - Check memory usage.
      - Forget to clear or destroy stuff?
      - > `vector::shrink_to_fit()`
    - Stack overflow?
    - Bad pointer / array access?
      - Try `-fsanitize=address`
    - Division by zero? NaN's?
*/

提出情報

提出日時
問題 B - Greater Than Average
ユーザ henotrix
言語 C++ 20 (gcc 12.2)
得点 500
コード長 3285 Byte
結果 AC
実行時間 27 ms
メモリ 5592 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 500 / 500
結果
AC × 1
AC × 86
セット名 テストケース
Sample 01_sample_01.txt
All 01_sample_01.txt, 02_small_1_01.txt, 02_small_1_02.txt, 02_small_1_03.txt, 02_small_1_04.txt, 02_small_1_05.txt, 02_small_1_06.txt, 02_small_1_07.txt, 02_small_1_08.txt, 02_small_1_09.txt, 02_small_1_10.txt, 02_small_1_11.txt, 02_small_1_12.txt, 02_small_1_13.txt, 02_small_1_14.txt, 02_small_1_15.txt, 03_small_2_01.txt, 03_small_2_02.txt, 03_small_2_03.txt, 03_small_2_04.txt, 03_small_2_05.txt, 04_small_3_01.txt, 04_small_3_02.txt, 04_small_3_03.txt, 04_small_3_04.txt, 04_small_3_05.txt, 05_mid_1_01.txt, 05_mid_1_02.txt, 05_mid_1_03.txt, 05_mid_1_04.txt, 05_mid_1_05.txt, 05_mid_1_06.txt, 05_mid_1_07.txt, 05_mid_1_08.txt, 05_mid_1_09.txt, 05_mid_1_10.txt, 05_mid_1_11.txt, 05_mid_1_12.txt, 05_mid_1_13.txt, 05_mid_1_14.txt, 05_mid_1_15.txt, 06_mid_2_01.txt, 06_mid_2_02.txt, 06_mid_2_03.txt, 06_mid_2_04.txt, 06_mid_2_05.txt, 07_mid_3_01.txt, 07_mid_3_02.txt, 07_mid_3_03.txt, 07_mid_3_04.txt, 07_mid_3_05.txt, 08_max_1_01.txt, 08_max_1_02.txt, 08_max_1_03.txt, 08_max_1_04.txt, 08_max_1_05.txt, 08_max_1_06.txt, 08_max_1_07.txt, 08_max_1_08.txt, 08_max_1_09.txt, 08_max_1_10.txt, 08_max_1_11.txt, 08_max_1_12.txt, 08_max_1_13.txt, 08_max_1_14.txt, 08_max_1_15.txt, 09_max_2_01.txt, 09_max_2_02.txt, 09_max_2_03.txt, 09_max_2_04.txt, 09_max_2_05.txt, 09_max_2_06.txt, 09_max_2_07.txt, 09_max_2_08.txt, 09_max_2_09.txt, 09_max_2_10.txt, 10_max_3_01.txt, 10_max_3_02.txt, 10_max_3_03.txt, 10_max_3_04.txt, 10_max_3_05.txt, 10_max_3_06.txt, 10_max_3_07.txt, 10_max_3_08.txt, 10_max_3_09.txt, 10_max_3_10.txt
ケース名 結果 実行時間 メモリ
01_sample_01.txt AC 1 ms 3508 KiB
02_small_1_01.txt AC 18 ms 3452 KiB
02_small_1_02.txt AC 18 ms 3520 KiB
02_small_1_03.txt AC 18 ms 3516 KiB
02_small_1_04.txt AC 18 ms 3644 KiB
02_small_1_05.txt AC 18 ms 3456 KiB
02_small_1_06.txt AC 18 ms 3496 KiB
02_small_1_07.txt AC 18 ms 3508 KiB
02_small_1_08.txt AC 18 ms 3644 KiB
02_small_1_09.txt AC 18 ms 3440 KiB
02_small_1_10.txt AC 18 ms 3516 KiB
02_small_1_11.txt AC 18 ms 3384 KiB
02_small_1_12.txt AC 17 ms 3456 KiB
02_small_1_13.txt AC 18 ms 3580 KiB
02_small_1_14.txt AC 18 ms 3416 KiB
02_small_1_15.txt AC 18 ms 3416 KiB
03_small_2_01.txt AC 18 ms 3508 KiB
03_small_2_02.txt AC 17 ms 3444 KiB
03_small_2_03.txt AC 17 ms 3512 KiB
03_small_2_04.txt AC 17 ms 3440 KiB
03_small_2_05.txt AC 17 ms 3436 KiB
04_small_3_01.txt AC 17 ms 3516 KiB
04_small_3_02.txt AC 17 ms 3508 KiB
04_small_3_03.txt AC 17 ms 3456 KiB
04_small_3_04.txt AC 17 ms 3516 KiB
04_small_3_05.txt AC 17 ms 3516 KiB
05_mid_1_01.txt AC 19 ms 3556 KiB
05_mid_1_02.txt AC 19 ms 3452 KiB
05_mid_1_03.txt AC 19 ms 3476 KiB
05_mid_1_04.txt AC 19 ms 3536 KiB
05_mid_1_05.txt AC 19 ms 3644 KiB
05_mid_1_06.txt AC 19 ms 3544 KiB
05_mid_1_07.txt AC 19 ms 3564 KiB
05_mid_1_08.txt AC 19 ms 3552 KiB
05_mid_1_09.txt AC 19 ms 3556 KiB
05_mid_1_10.txt AC 19 ms 3644 KiB
05_mid_1_11.txt AC 19 ms 3456 KiB
05_mid_1_12.txt AC 19 ms 3548 KiB
05_mid_1_13.txt AC 19 ms 3556 KiB
05_mid_1_14.txt AC 19 ms 3636 KiB
05_mid_1_15.txt AC 19 ms 3480 KiB
06_mid_2_01.txt AC 15 ms 3420 KiB
06_mid_2_02.txt AC 15 ms 3684 KiB
06_mid_2_03.txt AC 14 ms 3556 KiB
06_mid_2_04.txt AC 14 ms 3428 KiB
06_mid_2_05.txt AC 15 ms 3492 KiB
07_mid_3_01.txt AC 18 ms 3504 KiB
07_mid_3_02.txt AC 18 ms 3680 KiB
07_mid_3_03.txt AC 18 ms 3532 KiB
07_mid_3_04.txt AC 18 ms 3476 KiB
07_mid_3_05.txt AC 18 ms 3456 KiB
08_max_1_01.txt AC 27 ms 5428 KiB
08_max_1_02.txt AC 26 ms 5496 KiB
08_max_1_03.txt AC 26 ms 5460 KiB
08_max_1_04.txt AC 27 ms 5492 KiB
08_max_1_05.txt AC 26 ms 5384 KiB
08_max_1_06.txt AC 26 ms 5460 KiB
08_max_1_07.txt AC 27 ms 5404 KiB
08_max_1_08.txt AC 26 ms 5372 KiB
08_max_1_09.txt AC 26 ms 5592 KiB
08_max_1_10.txt AC 27 ms 5404 KiB
08_max_1_11.txt AC 26 ms 5492 KiB
08_max_1_12.txt AC 26 ms 5444 KiB
08_max_1_13.txt AC 27 ms 5496 KiB
08_max_1_14.txt AC 26 ms 5348 KiB
08_max_1_15.txt AC 26 ms 5420 KiB
09_max_2_01.txt AC 13 ms 5352 KiB
09_max_2_02.txt AC 15 ms 5416 KiB
09_max_2_03.txt AC 16 ms 5492 KiB
09_max_2_04.txt AC 16 ms 5428 KiB
09_max_2_05.txt AC 16 ms 5428 KiB
09_max_2_06.txt AC 17 ms 5400 KiB
09_max_2_07.txt AC 17 ms 5388 KiB
09_max_2_08.txt AC 17 ms 5428 KiB
09_max_2_09.txt AC 16 ms 5440 KiB
09_max_2_10.txt AC 18 ms 5444 KiB
10_max_3_01.txt AC 27 ms 5500 KiB
10_max_3_02.txt AC 20 ms 5436 KiB
10_max_3_03.txt AC 25 ms 5428 KiB
10_max_3_04.txt AC 23 ms 5460 KiB
10_max_3_05.txt AC 26 ms 5424 KiB
10_max_3_06.txt AC 24 ms 5408 KiB
10_max_3_07.txt AC 25 ms 5400 KiB
10_max_3_08.txt AC 18 ms 5424 KiB
10_max_3_09.txt AC 24 ms 5488 KiB
10_max_3_10.txt AC 24 ms 5376 KiB