48822023-04-05 22:08:47SleepyOverlordBányász RPG (40 pont)cpp17Wrong answer 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;
}
SubtaskSumTestVerdictTimeMemory
base24/40
1Accepted0/03ms1892 KiB
2Accepted0/014ms2328 KiB
3Accepted2/22ms2168 KiB
4Accepted2/23ms2200 KiB
5Wrong answer0/212ms2640 KiB
6Wrong answer0/223ms2848 KiB
7Wrong answer0/24ms2696 KiB
8Wrong answer0/26ms3040 KiB
9Accepted3/33ms3044 KiB
10Accepted3/33ms3288 KiB
11Accepted3/32ms3468 KiB
12Accepted3/33ms3556 KiB
13Accepted4/43ms3556 KiB
14Accepted4/43ms3664 KiB
15Wrong answer0/239ms4492 KiB
16Wrong answer0/252ms4880 KiB
17Wrong answer0/243ms4736 KiB
18Wrong answer0/268ms5456 KiB