#include "shortcut.h"
#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <int, pii> pip;
typedef pair <pii, int> ppi;
typedef pair <ll, ll> pll;
const int INF=0x3f3f3f3f;
const int N=3e5+5;
ll sum[N];
ll pref[N], suff[N];
ll until[N], later[N];
#define DEBUG 0
long long find_shortcut(int n, vector<int> l, vector<int> d, int c) {
l.insert(l.begin(), 0);
sum[0]=0;
for (int i=1; i<n; ++i) sum[i]=sum[i-1]+l[i];
pref[0]=d[0];
until[0]=d[0];
for (int i=1; i<n; ++i) {
until[i]=max(until[i-1]+l[i], (ll)d[i]);
pref[i]=max(pref[i-1], until[i-1]+d[i]+l[i]);
}
suff[n-1]=d[n-1];
later[n-1]=d[n-1];
for (int i=n-2; i>=0; --i) {
later[i]=max(later[i+1]+l[i+1], (ll)d[i]);
suff[i]=max(suff[i+1], later[i+1]+d[i]+l[i+1]);
}
ll najv=-1;
int lef=-1, rig=-1;
for (int i=0; i<n; ++i) {
for (int j=i+1; j<n; ++j) {
ll curr=sum[j]-sum[i]+d[i]+d[j];
if (curr>najv || (curr==najv && j-i<rig-lef)) najv=curr, lef=i, rig=j;
}
}
#if DEBUG
printf("until: ");
for (int i=0; i<n; ++i) printf("%lld ", until[i]);
printf("\npref: ");
for (int i=0; i<n; ++i) printf("%lld ", pref[i]);
printf("\nlater: ");
for (int i=0; i<n; ++i) printf("%lld ", later[i]);
printf("\nsuff: ");
for (int i=0; i<n; ++i) printf("%lld ", suff[i]);
printf("\n\n");
#endif // DEBUG
ll sol=pref[n-1];
for (int i=lef; i<rig; ++i) {
for (int j=i+1; j<=rig; ++j) {
if (sum[j]-sum[i]<=c) continue;
ll maxi=max(pref[i], suff[j]);
maxi=max(maxi, until[i]+later[j]+c);
#if DEBUG
printf("i: %d, j: %d, maxi: %lld\n", i, j, maxi);
#endif
for (int k=i+1; k<j; ++k) {
ll curr1=min(sum[j]-sum[k]+d[k]+c+until[i], d[k]+sum[k]-sum[i]+until[i]);
maxi=max(maxi, curr1);
ll curr2=min(sum[k]-sum[i]+d[k]+c+later[j], d[k]+sum[j]-sum[k]+later[j]);
maxi=max(maxi, curr2);
#if DEBUG
printf("k: %d, prvo: %lld, drugo: %lld\n", k, curr1, curr2);
#endif // DEBUG
}
#if DEBUG
printf("ukupno ==================== %lld\n\n", maxi);
#endif
sol=min(sol, maxi);
}
}
return sol;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
500 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
364 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
364 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
1 ms |
364 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
1 ms |
364 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
1 ms |
364 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
1 ms |
364 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
1 ms |
364 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
1 ms |
364 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
1 ms |
364 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
1 ms |
364 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
1 ms |
364 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
0 ms |
364 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
1 ms |
364 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
1 ms |
364 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
1 ms |
364 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
1 ms |
364 KB |
n = 10, 1000000343 is a correct answer |
18 |
Correct |
0 ms |
364 KB |
n = 10, 3189 is a correct answer |
19 |
Correct |
1 ms |
512 KB |
n = 10, 7000000000 is a correct answer |
20 |
Correct |
1 ms |
364 KB |
n = 5, 12 is a correct answer |
21 |
Correct |
1 ms |
364 KB |
n = 5, 25 is a correct answer |
22 |
Correct |
1 ms |
364 KB |
n = 2, 122 is a correct answer |
23 |
Correct |
1 ms |
364 KB |
n = 10, 117 is a correct answer |
24 |
Incorrect |
1 ms |
364 KB |
n = 10, incorrect answer: jury 336 vs contestant 333 |
25 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
500 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
364 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
364 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
1 ms |
364 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
1 ms |
364 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
1 ms |
364 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
1 ms |
364 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
1 ms |
364 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
1 ms |
364 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
1 ms |
364 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
1 ms |
364 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
1 ms |
364 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
0 ms |
364 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
1 ms |
364 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
1 ms |
364 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
1 ms |
364 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
1 ms |
364 KB |
n = 10, 1000000343 is a correct answer |
18 |
Correct |
0 ms |
364 KB |
n = 10, 3189 is a correct answer |
19 |
Correct |
1 ms |
512 KB |
n = 10, 7000000000 is a correct answer |
20 |
Correct |
1 ms |
364 KB |
n = 5, 12 is a correct answer |
21 |
Correct |
1 ms |
364 KB |
n = 5, 25 is a correct answer |
22 |
Correct |
1 ms |
364 KB |
n = 2, 122 is a correct answer |
23 |
Correct |
1 ms |
364 KB |
n = 10, 117 is a correct answer |
24 |
Incorrect |
1 ms |
364 KB |
n = 10, incorrect answer: jury 336 vs contestant 333 |
25 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
500 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
364 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
364 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
1 ms |
364 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
1 ms |
364 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
1 ms |
364 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
1 ms |
364 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
1 ms |
364 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
1 ms |
364 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
1 ms |
364 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
1 ms |
364 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
1 ms |
364 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
0 ms |
364 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
1 ms |
364 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
1 ms |
364 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
1 ms |
364 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
1 ms |
364 KB |
n = 10, 1000000343 is a correct answer |
18 |
Correct |
0 ms |
364 KB |
n = 10, 3189 is a correct answer |
19 |
Correct |
1 ms |
512 KB |
n = 10, 7000000000 is a correct answer |
20 |
Correct |
1 ms |
364 KB |
n = 5, 12 is a correct answer |
21 |
Correct |
1 ms |
364 KB |
n = 5, 25 is a correct answer |
22 |
Correct |
1 ms |
364 KB |
n = 2, 122 is a correct answer |
23 |
Correct |
1 ms |
364 KB |
n = 10, 117 is a correct answer |
24 |
Incorrect |
1 ms |
364 KB |
n = 10, incorrect answer: jury 336 vs contestant 333 |
25 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
500 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
364 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
364 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
1 ms |
364 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
1 ms |
364 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
1 ms |
364 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
1 ms |
364 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
1 ms |
364 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
1 ms |
364 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
1 ms |
364 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
1 ms |
364 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
1 ms |
364 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
0 ms |
364 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
1 ms |
364 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
1 ms |
364 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
1 ms |
364 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
1 ms |
364 KB |
n = 10, 1000000343 is a correct answer |
18 |
Correct |
0 ms |
364 KB |
n = 10, 3189 is a correct answer |
19 |
Correct |
1 ms |
512 KB |
n = 10, 7000000000 is a correct answer |
20 |
Correct |
1 ms |
364 KB |
n = 5, 12 is a correct answer |
21 |
Correct |
1 ms |
364 KB |
n = 5, 25 is a correct answer |
22 |
Correct |
1 ms |
364 KB |
n = 2, 122 is a correct answer |
23 |
Correct |
1 ms |
364 KB |
n = 10, 117 is a correct answer |
24 |
Incorrect |
1 ms |
364 KB |
n = 10, incorrect answer: jury 336 vs contestant 333 |
25 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
500 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
364 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
364 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
1 ms |
364 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
1 ms |
364 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
1 ms |
364 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
1 ms |
364 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
1 ms |
364 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
1 ms |
364 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
1 ms |
364 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
1 ms |
364 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
1 ms |
364 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
0 ms |
364 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
1 ms |
364 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
1 ms |
364 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
1 ms |
364 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
1 ms |
364 KB |
n = 10, 1000000343 is a correct answer |
18 |
Correct |
0 ms |
364 KB |
n = 10, 3189 is a correct answer |
19 |
Correct |
1 ms |
512 KB |
n = 10, 7000000000 is a correct answer |
20 |
Correct |
1 ms |
364 KB |
n = 5, 12 is a correct answer |
21 |
Correct |
1 ms |
364 KB |
n = 5, 25 is a correct answer |
22 |
Correct |
1 ms |
364 KB |
n = 2, 122 is a correct answer |
23 |
Correct |
1 ms |
364 KB |
n = 10, 117 is a correct answer |
24 |
Incorrect |
1 ms |
364 KB |
n = 10, incorrect answer: jury 336 vs contestant 333 |
25 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
500 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
364 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
364 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
1 ms |
364 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
1 ms |
364 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
1 ms |
364 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
1 ms |
364 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
1 ms |
364 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
1 ms |
364 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
1 ms |
364 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
1 ms |
364 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
1 ms |
364 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
0 ms |
364 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
1 ms |
364 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
1 ms |
364 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
1 ms |
364 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
1 ms |
364 KB |
n = 10, 1000000343 is a correct answer |
18 |
Correct |
0 ms |
364 KB |
n = 10, 3189 is a correct answer |
19 |
Correct |
1 ms |
512 KB |
n = 10, 7000000000 is a correct answer |
20 |
Correct |
1 ms |
364 KB |
n = 5, 12 is a correct answer |
21 |
Correct |
1 ms |
364 KB |
n = 5, 25 is a correct answer |
22 |
Correct |
1 ms |
364 KB |
n = 2, 122 is a correct answer |
23 |
Correct |
1 ms |
364 KB |
n = 10, 117 is a correct answer |
24 |
Incorrect |
1 ms |
364 KB |
n = 10, incorrect answer: jury 336 vs contestant 333 |
25 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
500 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
364 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
364 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
1 ms |
364 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
1 ms |
364 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
1 ms |
364 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
1 ms |
364 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
1 ms |
364 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
1 ms |
364 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
1 ms |
364 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
1 ms |
364 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
1 ms |
364 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
0 ms |
364 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
1 ms |
364 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
1 ms |
364 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
1 ms |
364 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
1 ms |
364 KB |
n = 10, 1000000343 is a correct answer |
18 |
Correct |
0 ms |
364 KB |
n = 10, 3189 is a correct answer |
19 |
Correct |
1 ms |
512 KB |
n = 10, 7000000000 is a correct answer |
20 |
Correct |
1 ms |
364 KB |
n = 5, 12 is a correct answer |
21 |
Correct |
1 ms |
364 KB |
n = 5, 25 is a correct answer |
22 |
Correct |
1 ms |
364 KB |
n = 2, 122 is a correct answer |
23 |
Correct |
1 ms |
364 KB |
n = 10, 117 is a correct answer |
24 |
Incorrect |
1 ms |
364 KB |
n = 10, incorrect answer: jury 336 vs contestant 333 |
25 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
500 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
364 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
364 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
1 ms |
364 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
1 ms |
364 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
1 ms |
364 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
1 ms |
364 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
1 ms |
364 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
1 ms |
364 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
1 ms |
364 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
1 ms |
364 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
1 ms |
364 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
0 ms |
364 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
1 ms |
364 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
1 ms |
364 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
1 ms |
364 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
1 ms |
364 KB |
n = 10, 1000000343 is a correct answer |
18 |
Correct |
0 ms |
364 KB |
n = 10, 3189 is a correct answer |
19 |
Correct |
1 ms |
512 KB |
n = 10, 7000000000 is a correct answer |
20 |
Correct |
1 ms |
364 KB |
n = 5, 12 is a correct answer |
21 |
Correct |
1 ms |
364 KB |
n = 5, 25 is a correct answer |
22 |
Correct |
1 ms |
364 KB |
n = 2, 122 is a correct answer |
23 |
Correct |
1 ms |
364 KB |
n = 10, 117 is a correct answer |
24 |
Incorrect |
1 ms |
364 KB |
n = 10, incorrect answer: jury 336 vs contestant 333 |
25 |
Halted |
0 ms |
0 KB |
- |