48832023-04-05 22:29:06SleepyOverlordBányász RPG (40 pont)cpp17Elfogadva 40/4065ms5072 KiB
#include <vector>
#include <string> 
#include <set> 
#include <map> 
#include <unordered_set>
#include <unordered_map>
#include <queue> 
#include <bitset> 
#include <stack>
#include <list>

#include <numeric> 
#include <algorithm> 
#include <random>
#include <chrono>

#include <cstdio>
#include <fstream>
#include <iostream> 
#include <sstream> 
#include <iomanip>
#include <climits>

#include <cctype>
#include <cmath> 
#include <ctime>
#include <cassert>

using namespace std;

#define ULL unsigned long long
#define LL long long
#define PII pair <int, int>
#define VB vector <bool>
#define VI vector <int>
#define VLL vector <LL>
#define VD vector <double>
#define VS vector <string>
#define VPII vector <pair <int, int> >
#define VVI vector < VI >
#define VVB vector < VB >
#define SI set < int >
#define USI unordered_set <int>
#define MII map <int, int>
#define UMII unordered_map <int, int>
#define MS multiset
#define US unordered_set
#define UM unordered_map
#define UMS unordered_multiset
#define UMM unordered_multimap

#define FORN(i, n) for(int i = 0; i < (n); ++i)
#define FOR(i, a, b) for(int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)

#define SZ size()
#define BG begin() 
#define EN end() 
#define CL clear()
#define X first
#define Y second
#define RS resize
#define PB push_back
#define MP make_pair
#define ALL(x) x.begin(), x.end()
#define INS insert
#define ER erase
#define CNT count

int n;
VPII a;

int main()
{
	cin >> n;
	a.RS(n + 1);

	FOR(i, 1, n) cin >> a[i].X;
	FOR(i, 1, n) cin >> a[i].Y;

	sort(a.BG + 1, a.EN);
	ULL experience = 0, time = 0;
	int j = n;
	while (j > 1 && experience < a[1].X)
	{
		if (experience + a[j].Y < a[1].X)
		{
			time += a[j].Y * 2;
			experience += a[j].Y;
			a[j].Y = 0;
		}
		else
		{
			time += (a[1].X - experience) * 2;
			a[j].Y -= (a[1].X - experience);
			experience = a[1].X;
		}
		--j;
	}
	FOR(i, 1, n) 
	{
		if (a[i].X > experience) 
			if (experience + a[i].Y <= a[i].X) time += a[i].Y * 2;
			else time += (a[i].X - experience) * 2 + a[i].Y - (a[i].X - experience);
		else time += a[i].Y;
		experience += a[i].Y;
	}

	cout << time;

	return 0;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base40/40
1Elfogadva0/03ms1880 KiB
2Elfogadva0/014ms2368 KiB
3Elfogadva2/22ms2176 KiB
4Elfogadva2/23ms2388 KiB
5Elfogadva2/212ms2820 KiB
6Elfogadva2/221ms2980 KiB
7Elfogadva2/24ms2824 KiB
8Elfogadva2/26ms3176 KiB
9Elfogadva3/33ms3348 KiB
10Elfogadva3/33ms3432 KiB
11Elfogadva3/32ms3440 KiB
12Elfogadva3/33ms3448 KiB
13Elfogadva4/43ms3452 KiB
14Elfogadva4/43ms3328 KiB
15Elfogadva2/237ms4020 KiB
16Elfogadva2/250ms4284 KiB
17Elfogadva2/241ms4488 KiB
18Elfogadva2/265ms5072 KiB