48822023-04-05 22:08:47SleepyOverlordBányász RPG (40 pont)cpp17Hibás válasz 24/4068ms5456 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;
	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;
		else time += a[i].Y;
		experience += a[i].Y;
	}

	ULL time1 = time;
	reverse(a.BG + 1, a.EN);
	experience = 0, time = 0;
	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;
		else time += a[i].Y;
		experience += a[i].Y;
	}

	cout << min(time, time1);

	return 0;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base24/40
1Elfogadva0/03ms1892 KiB
2Elfogadva0/014ms2328 KiB
3Elfogadva2/22ms2168 KiB
4Elfogadva2/23ms2200 KiB
5Hibás válasz0/212ms2640 KiB
6Hibás válasz0/223ms2848 KiB
7Hibás válasz0/24ms2696 KiB
8Hibás válasz0/26ms3040 KiB
9Elfogadva3/33ms3044 KiB
10Elfogadva3/33ms3288 KiB
11Elfogadva3/32ms3468 KiB
12Elfogadva3/33ms3556 KiB
13Elfogadva4/43ms3556 KiB
14Elfogadva4/43ms3664 KiB
15Hibás válasz0/239ms4492 KiB
16Hibás válasz0/252ms4880 KiB
17Hibás válasz0/243ms4736 KiB
18Hibás válasz0/268ms5456 KiB