57132023-09-09 18:58:20TomaSajtBányász RPG (40 pont)cpp17Elfogadva 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;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base40/40
1Elfogadva0/03ms1824 KiB
2Elfogadva0/08ms2372 KiB
3Elfogadva2/22ms2256 KiB
4Elfogadva2/23ms2604 KiB
5Elfogadva2/27ms3180 KiB
6Elfogadva2/213ms3888 KiB
7Elfogadva2/24ms3856 KiB
8Elfogadva2/24ms4128 KiB
9Elfogadva3/32ms4152 KiB
10Elfogadva3/33ms4368 KiB
11Elfogadva3/33ms4572 KiB
12Elfogadva3/33ms4684 KiB
13Elfogadva4/43ms5036 KiB
14Elfogadva4/43ms5212 KiB
15Elfogadva2/220ms6616 KiB
16Elfogadva2/227ms7528 KiB
17Elfogadva2/221ms8128 KiB
18Elfogadva2/232ms9604 KiB