49122023-04-06 23:19:30TomaSajtBányász RPG (40 pont)cpp17Accepted 40/4032ms5716 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

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;
  ll xp = 0;
  ll time = 0;
  while (l <= r) {
    if (v[l][0] <= xp) {
      time += v[l][1];
      xp += v[l][1];
      v[l][1] = 0;
      l++;
    } else {
      time += 2;
      xp++;
      v[r][1]--;
      if (v[r][1] == 0)
        r--;
    }
  }
  cout << time;
}
SubtaskSumTestVerdictTimeMemory
base40/40
1Accepted0/03ms1828 KiB
2Accepted0/08ms2312 KiB
3Accepted2/23ms2268 KiB
4Accepted2/23ms2488 KiB
5Accepted2/27ms2896 KiB
6Accepted2/213ms3208 KiB
7Accepted2/24ms3240 KiB
8Accepted2/24ms3588 KiB
9Accepted3/32ms3504 KiB
10Accepted3/32ms3384 KiB
11Accepted3/32ms3512 KiB
12Accepted3/33ms3744 KiB
13Accepted4/43ms3976 KiB
14Accepted4/43ms4168 KiB
15Accepted2/218ms4936 KiB
16Accepted2/225ms5068 KiB
17Accepted2/220ms4936 KiB
18Accepted2/232ms5716 KiB