Submission #33496977


Source Code Expand

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long

//#define debug(x) ;
#define debug(x) cerr << #x << " = " << x << "\n";

ostream& operator<<(ostream& cerr, vector<ll> aux) {
  cerr << "[";
  for (auto e : aux) cerr << e << ' ';
  cerr << "]";
  return cerr;
}

const int maxN = 300011;

ll n, a, b;
ll v[maxN];

bool check(ll limit) {
  ll to_add = 0;
  ll to_rm = 0;

  for (int i = 0; i < n; i++) {
    ll x = v[i];

    if (x < limit) {
      to_add += (limit - x + a - 1) / a;
    }

    if (x > limit) {
      to_rm += (x - limit) / b;
    }
  }

  return to_add <= to_rm;
}

int main()
{

  cin >> n >> a >> b;
  for (int i = 0; i < n; i++) 
    cin >> v[i];

  ll low = 0;
  ll high = 1e9 + 1;

  for (ll step = 1 << 30; step > 0; step >>= 1) 
    if (low + step < high) 
      if (check(low + step))
        low += step;

  cout << low;


  return 0;
}

Submission Info

Submission Time
Task B - Gift Tax
User atatomir
Language C++ (GCC 9.2.1)
Score 400
Code Size 1080 Byte
Status AC
Exec Time 190 ms
Memory 5932 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 4
AC × 76
Set Name Test Cases
Sample 01_sample_01.txt, 01_sample_02.txt, 01_sample_03.txt, 01_sample_04.txt
All 01_sample_01.txt, 01_sample_02.txt, 01_sample_03.txt, 01_sample_04.txt, 02_small_N_01.txt, 02_small_N_02.txt, 02_small_N_03.txt, 02_small_N_04.txt, 02_small_N_05.txt, 02_small_N_06.txt, 02_small_N_07.txt, 02_small_N_08.txt, 02_small_N_09.txt, 03_rand_1_01.txt, 03_rand_1_02.txt, 03_rand_1_03.txt, 03_rand_1_04.txt, 03_rand_1_05.txt, 03_rand_1_06.txt, 03_rand_1_07.txt, 03_rand_1_08.txt, 03_rand_1_09.txt, 03_rand_1_10.txt, 04_rand_2_01.txt, 04_rand_2_02.txt, 04_rand_2_03.txt, 04_rand_2_04.txt, 04_rand_2_05.txt, 04_rand_2_06.txt, 04_rand_2_07.txt, 04_rand_2_08.txt, 04_rand_2_09.txt, 04_rand_2_10.txt, 04_rand_2_11.txt, 04_rand_2_12.txt, 04_rand_2_13.txt, 04_rand_2_14.txt, 04_rand_2_15.txt, 04_rand_2_16.txt, 04_rand_2_17.txt, 04_rand_2_18.txt, 04_rand_2_19.txt, 04_rand_2_20.txt, 05_a_equal_b_01.txt, 05_a_equal_b_02.txt, 05_a_equal_b_03.txt, 05_a_equal_b_04.txt, 05_a_equal_b_05.txt, 05_a_equal_b_06.txt, 05_a_equal_b_07.txt, 05_a_equal_b_08.txt, 05_a_equal_b_09.txt, 05_a_equal_b_10.txt, 06_small_ab_01.txt, 06_small_ab_02.txt, 06_small_ab_03.txt, 06_small_ab_04.txt, 06_small_ab_05.txt, 06_small_ab_06.txt, 06_small_ab_07.txt, 06_small_ab_08.txt, 06_small_ab_09.txt, 06_small_ab_10.txt, 06_small_ab_11.txt, 06_small_ab_12.txt, 06_small_ab_13.txt, 06_small_ab_14.txt, 06_small_ab_15.txt, 06_small_ab_16.txt, 06_small_ab_17.txt, 06_small_ab_18.txt, 06_small_ab_19.txt, 06_small_ab_20.txt, 07_const_01.txt, 07_const_02.txt, 07_const_03.txt
Case Name Status Exec Time Memory
01_sample_01.txt AC 7 ms 3476 KiB
01_sample_02.txt AC 2 ms 3560 KiB
01_sample_03.txt AC 3 ms 3424 KiB
01_sample_04.txt AC 2 ms 3356 KiB
02_small_N_01.txt AC 3 ms 3476 KiB
02_small_N_02.txt AC 2 ms 3480 KiB
02_small_N_03.txt AC 3 ms 3572 KiB
02_small_N_04.txt AC 2 ms 3476 KiB
02_small_N_05.txt AC 2 ms 3436 KiB
02_small_N_06.txt AC 3 ms 3512 KiB
02_small_N_07.txt AC 2 ms 3416 KiB
02_small_N_08.txt AC 2 ms 3588 KiB
02_small_N_09.txt AC 2 ms 3572 KiB
03_rand_1_01.txt AC 169 ms 5768 KiB
03_rand_1_02.txt AC 169 ms 5856 KiB
03_rand_1_03.txt AC 181 ms 5716 KiB
03_rand_1_04.txt AC 176 ms 5760 KiB
03_rand_1_05.txt AC 175 ms 5904 KiB
03_rand_1_06.txt AC 175 ms 5772 KiB
03_rand_1_07.txt AC 164 ms 5928 KiB
03_rand_1_08.txt AC 179 ms 5692 KiB
03_rand_1_09.txt AC 171 ms 5884 KiB
03_rand_1_10.txt AC 172 ms 5816 KiB
04_rand_2_01.txt AC 152 ms 5820 KiB
04_rand_2_02.txt AC 153 ms 5856 KiB
04_rand_2_03.txt AC 160 ms 5884 KiB
04_rand_2_04.txt AC 155 ms 5772 KiB
04_rand_2_05.txt AC 154 ms 5900 KiB
04_rand_2_06.txt AC 155 ms 5904 KiB
04_rand_2_07.txt AC 155 ms 5720 KiB
04_rand_2_08.txt AC 159 ms 5856 KiB
04_rand_2_09.txt AC 154 ms 5716 KiB
04_rand_2_10.txt AC 154 ms 5912 KiB
04_rand_2_11.txt AC 152 ms 5884 KiB
04_rand_2_12.txt AC 160 ms 5928 KiB
04_rand_2_13.txt AC 162 ms 5852 KiB
04_rand_2_14.txt AC 160 ms 5816 KiB
04_rand_2_15.txt AC 151 ms 5856 KiB
04_rand_2_16.txt AC 153 ms 5772 KiB
04_rand_2_17.txt AC 156 ms 5768 KiB
04_rand_2_18.txt AC 157 ms 5884 KiB
04_rand_2_19.txt AC 162 ms 5928 KiB
04_rand_2_20.txt AC 160 ms 5852 KiB
05_a_equal_b_01.txt AC 185 ms 5900 KiB
05_a_equal_b_02.txt AC 177 ms 5760 KiB
05_a_equal_b_03.txt AC 183 ms 5860 KiB
05_a_equal_b_04.txt AC 185 ms 5860 KiB
05_a_equal_b_05.txt AC 178 ms 5856 KiB
05_a_equal_b_06.txt AC 168 ms 5900 KiB
05_a_equal_b_07.txt AC 181 ms 5932 KiB
05_a_equal_b_08.txt AC 184 ms 5760 KiB
05_a_equal_b_09.txt AC 177 ms 5856 KiB
05_a_equal_b_10.txt AC 171 ms 5900 KiB
06_small_ab_01.txt AC 190 ms 5852 KiB
06_small_ab_02.txt AC 186 ms 5720 KiB
06_small_ab_03.txt AC 181 ms 5932 KiB
06_small_ab_04.txt AC 187 ms 5904 KiB
06_small_ab_05.txt AC 187 ms 5816 KiB
06_small_ab_06.txt AC 186 ms 5816 KiB
06_small_ab_07.txt AC 176 ms 5756 KiB
06_small_ab_08.txt AC 185 ms 5772 KiB
06_small_ab_09.txt AC 187 ms 5852 KiB
06_small_ab_10.txt AC 187 ms 5856 KiB
06_small_ab_11.txt AC 180 ms 5860 KiB
06_small_ab_12.txt AC 186 ms 5856 KiB
06_small_ab_13.txt AC 186 ms 5716 KiB
06_small_ab_14.txt AC 187 ms 5720 KiB
06_small_ab_15.txt AC 181 ms 5720 KiB
06_small_ab_16.txt AC 190 ms 5856 KiB
06_small_ab_17.txt AC 187 ms 5908 KiB
06_small_ab_18.txt AC 184 ms 5716 KiB
06_small_ab_19.txt AC 187 ms 5880 KiB
06_small_ab_20.txt AC 186 ms 5896 KiB
07_const_01.txt AC 108 ms 5776 KiB
07_const_02.txt AC 122 ms 5764 KiB
07_const_03.txt AC 160 ms 5884 KiB