Submission #1821442


Source Code Expand

Copy
#include<iostream>
#include<fstream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<set>

using namespace std;
int n, k;
vector<long long> a, b;

typedef struct A {
  long long a, b;
} Node;

bool operator<(const Node &lhs, const Node &rhs) {
  return lhs.a < rhs.a;
}

int main() {
  cin >> n >> k;
  a.resize(n); b.resize(n);
  for(int i = 0; i < n; i++) cin >> a[i] >> b[i];
  multiset<Node> s;
  for(int i = 0; i < n; i++) {
    Node nw;
    nw.a = a[i];
    nw.b = b[i];
    s.insert(nw);
  }
  long long ans = 0;
  for(int i = 0; i < k; i++) {
    Node no = *s.begin();
    ans += no.a;
    Node next;
    next.a = no.a + no.b;
    next.b = no.b;
    s.erase(s.begin());
    s.insert(next);
  }
  cout << ans << endl;
	return 0;
}

Submission Info

Submission Time
Task C - Factory
User ninja7
Language C++14 (GCC 5.4.1)
Score 300
Code Size 867 Byte
Status
Exec Time 153 ms
Memory 8064 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 sample_01.txt, sample_02.txt, sample_03.txt
All 300 / 300 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 1 ms 256 KB
sample_02.txt 8 ms 256 KB
sample_03.txt 6 ms 256 KB
subtask_1_1.txt 1 ms 256 KB
subtask_1_10.txt 54 ms 4608 KB
subtask_1_11.txt 1 ms 256 KB
subtask_1_12.txt 101 ms 8064 KB
subtask_1_13.txt 1 ms 256 KB
subtask_1_14.txt 32 ms 2560 KB
subtask_1_15.txt 115 ms 8064 KB
subtask_1_16.txt 6 ms 256 KB
subtask_1_17.txt 6 ms 256 KB
subtask_1_18.txt 153 ms 8064 KB
subtask_1_2.txt 29 ms 1024 KB
subtask_1_3.txt 53 ms 4096 KB
subtask_1_4.txt 16 ms 384 KB
subtask_1_5.txt 111 ms 8064 KB
subtask_1_6.txt 17 ms 640 KB
subtask_1_7.txt 10 ms 256 KB
subtask_1_8.txt 143 ms 8064 KB
subtask_1_9.txt 129 ms 7168 KB