-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUVa11269.cpp
51 lines (49 loc) · 956 Bytes
/
UVa11269.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
// shortcuts for "common" data types in contests
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
#define INF 1000000000
bool comp(ii a, ii b)
{
int theMin = min({a.first, a.second, b.first, b.second});
if (theMin == a.first || theMin == b.second)
return true;
return false;
}
int main()
{
int p;
while (scanf("%d\n", &p) != EOF)
{
vii probs;
for (int i = 0; i < p; i++)
{
int a; scanf("%d", &a);
probs.push_back(make_pair(a, -1));
}
for (int i = 0; i < p; i++)
{
int b; scanf("%d", &b);
probs.at(i).second = b;
}
sort(probs.begin(), probs.end(), comp);
int time = 0;
int gwork = 0;
for (ii pb : probs)
{
time += pb.first;
gwork = max(0, gwork - pb.first);
gwork += pb.second;
}
time += gwork;
printf("%d\n", time);
}
return 0;
}