Submission #4074937


Source Code Expand

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

using P = pair<ll, ll>;

int main() {
  int N, K;
  while (cin >> N >> K) {
    vector<ll> a(N), b(N);
    for (int i = 0; i < N; i++) cin >> a[i] >> b[i];
    priority_queue<P, vector<P>, greater<P>> pq;
    for (int i = 0; i < N; i++) {
      pq.emplace(a[i], b[i]);
    }
    ll res = 0;
    for (int t = 0; t < K; t++) {
      P p = pq.top();
      pq.pop();
      res += p.fst;
      pq.emplace(p.fst + p.snd, p.snd);
    }
    cout << res << endl;
  }
  return 0;
}

Submission Info

Submission Time
Task C - Factory
User kroton
Language C++14 (GCC 5.4.1)
Score 300
Code Size 1548 Byte
Status AC
Exec Time 97 ms
Memory 3956 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 3
AC × 21
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All sample_01.txt, sample_02.txt, sample_03.txt, subtask_1_1.txt, subtask_1_10.txt, subtask_1_11.txt, subtask_1_12.txt, subtask_1_13.txt, subtask_1_14.txt, subtask_1_15.txt, subtask_1_16.txt, subtask_1_17.txt, subtask_1_18.txt, subtask_1_2.txt, subtask_1_3.txt, subtask_1_4.txt, subtask_1_5.txt, subtask_1_6.txt, subtask_1_7.txt, subtask_1_8.txt, subtask_1_9.txt
Case Name Status Exec Time Memory
sample_01.txt AC 1 ms 256 KB
sample_02.txt AC 5 ms 256 KB
sample_03.txt AC 3 ms 256 KB
subtask_1_1.txt AC 1 ms 256 KB
subtask_1_10.txt AC 41 ms 2296 KB
subtask_1_11.txt AC 1 ms 256 KB
subtask_1_12.txt AC 71 ms 3956 KB
subtask_1_13.txt AC 1 ms 256 KB
subtask_1_14.txt AC 26 ms 1276 KB
subtask_1_15.txt AC 87 ms 3956 KB
subtask_1_16.txt AC 3 ms 256 KB
subtask_1_17.txt AC 3 ms 256 KB
subtask_1_18.txt AC 95 ms 3956 KB
subtask_1_2.txt AC 19 ms 768 KB
subtask_1_3.txt AC 42 ms 2168 KB
subtask_1_4.txt AC 10 ms 256 KB
subtask_1_5.txt AC 83 ms 3956 KB
subtask_1_6.txt AC 13 ms 512 KB
subtask_1_7.txt AC 6 ms 256 KB
subtask_1_8.txt AC 97 ms 3956 KB
subtask_1_9.txt AC 87 ms 3828 KB