QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#30539#2464. Taxed Editorsinbad#AC ✓153ms6672kbC++174.5kb2022-04-29 22:34:192022-04-29 22:34:21

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-04-29 22:34:21]
  • 评测
  • 测评结果:AC
  • 用时:153ms
  • 内存:6672kb
  • [2022-04-29 22:34:19]
  • 提交

answer

#define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const multiset<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
  return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

template <class T> auto vect(const T& v, int n) { return vector<T>(n, v); }
template <class T, class... D> auto vect(const T& v, int n, D... m) {
  return vector<decltype(vect(v, m...))>(n, vect(v, m...));
}

using int64 = long long;
using int128 = __int128_t;
using ii = pair<int, int>;
#define SZ(x) (int)((x).size())
template <typename T> static constexpr T inf = numeric_limits<T>::max() / 2;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
// mt19937 mrand(random_device{}());
// int rnd(int x) { return mrand() % x; }
mt19937_64 mrand(random_device{}());
int64 rnd(int64 x) { return mrand() % x; }
int lg2(int64 x) { return sizeof(int64) * 8 - 1 - __builtin_clzll(x); }
template <class T> void out(const vector<T>& a) { for (int i = 0; i < SZ(a); ++i) cout << a[i] << " \n"[i + 1 == SZ(a)]; }
template <class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template <class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
template <class T> void dedup(vector<T>& v) { sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); }
void add_mod(int& x, int y) { x += y; if (x >= MOD) x -= MOD; }
void sub_mod(int& x, int y) { x += MOD - y; if (x >= MOD) x -= MOD; }

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

int main() {
  int n, m;
  cin >> n >> m;
  m = n - m;

  vector<array<int64, 2>> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i][0] >> a[i][1];
  sort(a.begin(), a.end(),
       [&](const auto& L, const auto& R) {
         return L[1] < R[1];
       });

  int64 low = 1, high = 1e14;
  while (low != high) {
    int64 mid = (low + high) / 2;
    priority_queue<int64> Q;
    int64 sum = 0, cnt = 0;
    for (auto& [len, d] : a) {
      // trace(mid, len, d, sum);
      if (mid * d - sum >= len) {
        ++cnt;
        sum += len;
        Q.push(len);
      } else {
        if (Q.size() && sum - Q.top() + len < sum) {
          sum = sum - Q.top() + len;
          Q.pop();
          Q.push(len);
        }
      }
    }
    if (cnt < m) {
      low = mid + 1;
    } else {
      high = mid;
    }
  }
  cout << high << '\n';
  return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 4ms
memory: 3720kb

input:

100 0
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 ...

output:

100

result:

ok single line: '100'

Test #2:

score: 0
Accepted
time: 3ms
memory: 3644kb

input:

100 0
1 1
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
1 21
1 22
1 23
1 24
1 25
1 26
1 27
1 28
1 29
1 30
1 31
1 32
1 33
1 34
1 35
1 36
1 37
1 38
1 39
1 40
1 41
1 42
1 43
1 44
1 45
1 46
1 47
1 48
1 49
1 50
1 51
1 52
1 53
1 54
1 55
1 56
1 57
1 58
1 59
1 60
1 6...

output:

1

result:

ok single line: '1'

Test #3:

score: 0
Accepted
time: 1ms
memory: 3660kb

input:

100 99
1 1
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
1 21
1 22
1 23
1 24
1 25
1 26
1 27
1 28
1 29
1 30
1 31
1 32
1 33
1 34
1 35
1 36
1 37
1 38
1 39
1 40
1 41
1 42
1 43
1 44
1 45
1 46
1 47
1 48
1 49
1 50
1 51
1 52
1 53
1 54
1 55
1 56
1 57
1 58
1 59
1 60
1 ...

output:

1

result:

ok single line: '1'

Test #4:

score: 0
Accepted
time: 3ms
memory: 3660kb

input:

100 0
1 40
1 41
1 42
1 3
1 20
1 4
1 5
1 86
1 87
1 13
1 14
1 1
1 15
1 16
1 18
1 19
1 21
1 22
1 93
1 94
1 74
1 95
1 96
1 23
1 25
1 29
1 30
1 31
1 53
1 54
1 88
1 89
1 17
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 75
1 55
1 56
1 57
1 58
1 59
1 60
1 61
1 62
1 63
1 64
1 65
1 66
1 67
1 68
1 69
1 70
1 71
1 72
1 73
1 ...

output:

1

result:

ok single line: '1'

Test #5:

score: 0
Accepted
time: 3ms
memory: 3716kb

input:

100 0
2 40
2 41
2 42
2 3
2 20
2 4
2 5
2 86
2 87
2 13
2 14
2 1
2 15
2 16
2 18
2 19
2 21
2 22
2 93
2 94
2 74
2 95
2 96
2 23
2 25
2 29
2 30
2 31
2 53
2 54
2 88
2 89
2 17
2 6
2 7
2 8
2 9
2 10
2 11
2 12
2 75
2 55
2 56
2 57
2 58
2 59
2 60
2 61
2 62
2 63
2 64
2 65
2 66
2 67
2 68
2 69
2 70
2 71
2 72
2 73
2 ...

output:

2

result:

ok single line: '2'

Test #6:

score: 0
Accepted
time: 3ms
memory: 3716kb

input:

100 1
2 40
2 41
2 42
2 3
2 20
2 4
2 5
2 86
2 87
2 13
2 14
2 1
2 15
2 16
2 18
2 19
2 21
2 22
2 93
2 94
2 74
2 95
2 96
2 23
2 25
2 29
2 30
2 31
2 53
2 54
2 88
2 89
2 17
2 6
2 7
2 8
2 9
2 10
2 11
2 12
2 75
2 55
2 56
2 57
2 58
2 59
2 60
2 61
2 62
2 63
2 64
2 65
2 66
2 67
2 68
2 69
2 70
2 71
2 72
2 73
2 ...

output:

2

result:

ok single line: '2'

Test #7:

score: 0
Accepted
time: 3ms
memory: 3584kb

input:

100 50
2 40
2 41
2 42
2 3
2 20
2 4
2 5
2 86
2 87
2 13
2 14
2 1
2 15
2 16
2 18
2 19
2 21
2 22
2 93
2 94
2 74
2 95
2 96
2 23
2 25
2 29
2 30
2 31
2 53
2 54
2 88
2 89
2 17
2 6
2 7
2 8
2 9
2 10
2 11
2 12
2 75
2 55
2 56
2 57
2 58
2 59
2 60
2 61
2 62
2 63
2 64
2 65
2 66
2 67
2 68
2 69
2 70
2 71
2 72
2 73
2...

output:

1

result:

ok single line: '1'

Test #8:

score: 0
Accepted
time: 31ms
memory: 6672kb

input:

100000 0
1000000000 1
1000000000 1
1000000000 1
1000000000 1
1000000000 1
1000000000 1
1000000000 1
1000000000 1
1000000000 1
1000000000 1
1000000000 1
1000000000 1
1000000000 1
1000000000 1
1000000000 1
1000000000 1
1000000000 1
1000000000 1
1000000000 1
1000000000 1
1000000000 1
1000000000 1
10000...

output:

100000000000000

result:

ok single line: '100000000000000'

Test #9:

score: 0
Accepted
time: 65ms
memory: 4772kb

input:

46786 26474
972646846 4838
253000777 9895
844739410 3953
740725829 2432
569863348 8835
775252385 8003
346981464 6141
305937051 1941
499745631 6513
398984816 9556
387704708 890
89926161 9661
760454705 2946
910581384 3616
946296579 5216
964100071 7349
178904063 104
732671873 9766
468959891 3677
214314...

output:

442908028

result:

ok single line: '442908028'

Test #10:

score: 0
Accepted
time: 3ms
memory: 3664kb

input:

3 1
450 9
500 6
300 4

output:

84

result:

ok single line: '84'

Test #11:

score: 0
Accepted
time: 124ms
memory: 6124kb

input:

81309 13105
512549036 5388
583961403 7878
110696896 3661
731681027 4653
337863237 4567
548796175 5675
190209109 7645
815384070 5308
202574729 6532
78478209 3793
661679100 454
538303356 1718
109054503 221
374399737 7036
377635569 6195
224409233 5851
224768256 6805
292807834 3126
112440792 2998
160795...

output:

2841922681

result:

ok single line: '2841922681'

Test #12:

score: 0
Accepted
time: 153ms
memory: 6092kb

input:

86721 26489
894760820 3552
871291232 2650
552121265 4036
435080577 8784
384159611 4477
718837434 8253
744757790 8434
28957327 8793
938435157 2703
516771922 2576
736642972 5469
798577299 5740
949187275 60
647392841 8964
131345535 3787
231773479 6867
254396458 6066
386077792 3047
939085239 7036
455227...

output:

2090454962

result:

ok single line: '2090454962'

Test #13:

score: 0
Accepted
time: 100ms
memory: 5112kb

input:

53057 17674
79202175 4880
898335481 9387
127229311 9889
984428283 7633
486305793 5920
722051684 8168
4727594 1857
392726961 9133
803862897 2796
74446345 5179
498235459 1103
10664792 3352
741667933 1779
808193631 7524
268541298 6149
478158729 2613
489066136 6682
149571745 9911
689142821 2273
77793397...

output:

1176575271

result:

ok single line: '1176575271'