57132023-09-09 18:58:20TomaSajtBányász RPG (40 pont)cpp17Accepted 40/4032ms9604 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
  cin.tie(0), cin.sync_with_stdio(0);

  int n;
  cin >> n;

  vector<array<int, 2>> v(n);
  for (int i = 0; i < n; i++) cin >> v[i][0];
  for (int i = 0; i < n; i++) cin >> v[i][1];

  sort(v.begin(), v.end());

  int l = 0, r = n - 1;
  long long xp = 0, time = 0;
  while (l <= r) {
    // collect resource with lowest xp requirement, if it is met
    if (v[l][0] <= xp) {
      time += v[l][1];
      xp += v[l][1];
      v[l][1] = 0;
      l++;
    }
    // else collect the resource with the xp requirement that is the most unlikely to be met (the highest)
    else {
      time += 2;
      xp++;
      v[r][1]--;
      if (v[r][1] == 0) r--;
    }
  }
  cout << time;
}
SubtaskSumTestVerdictTimeMemory
base40/40
1Accepted0/03ms1824 KiB
2Accepted0/08ms2372 KiB
3Accepted2/22ms2256 KiB
4Accepted2/23ms2604 KiB
5Accepted2/27ms3180 KiB
6Accepted2/213ms3888 KiB
7Accepted2/24ms3856 KiB
8Accepted2/24ms4128 KiB
9Accepted3/32ms4152 KiB
10Accepted3/33ms4368 KiB
11Accepted3/33ms4572 KiB
12Accepted3/33ms4684 KiB
13Accepted4/43ms5036 KiB
14Accepted4/43ms5212 KiB
15Accepted2/220ms6616 KiB
16Accepted2/227ms7528 KiB
17Accepted2/221ms8128 KiB
18Accepted2/232ms9604 KiB