#include "shortcut.h"
#include <iostream>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <fstream>
#include <cmath>
#include <vector>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <stack>
#include <queue>
#include <assert.h>
#include <limits>
#include <cstdio>
#include <complex>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef string str;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
#define mp make_pair
#define f first
#define s second
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<pd> vpd;
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define pf push_front
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)
const int MOD = 1e9+7; // 998244353; // = (119<<23)+1
const int MX = 3e3+5;
const ll INF = 1e18;
const ld PI = 4*atan((ld)1);
const int dx[4] = {0,1,0,-1}, dy[4] = {1,0,-1,0};
namespace io {
void setIn(string s) { freopen(s.c_str(),"r",stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }
void setIO(string s = "") {
ios_base::sync_with_stdio(0); cin.tie(0); // fast I/O
// cin.exceptions(cin.failbit); // ex. throws exception when you try to read letter into int
if (sz(s)) {
setIn(s+".in");
setOut(s+".out");
} // for USACO
}
}
using namespace io;
namespace input {
template<class T> void re(complex<T>& x);
template<class T1, class T2> void re(pair<T1,T2>& p);
template<class T> void re(vector<T>& a);
template<class T, size_t SZ> void re(array<T,SZ>& a);
template<class T> void re(T& x) { cin >> x; }
void re(double& x) { string t; re(t); x = stod(t); }
void re(ld& x) { string t; re(t); x = stold(t); }
template<class Arg, class... Args> void re(Arg& first, Args&... rest) {
re(first); re(rest...);
}
template<class T> void re(complex<T>& x) { T a,b; re(a,b); x = cd(a,b); }
template<class T1, class T2> void re(pair<T1,T2>& p) { re(p.f,p.s); }
template<class T> void re(vector<T>& a) { F0R(i,sz(a)) re(a[i]); }
template<class T, size_t SZ> void re(array<T,SZ>& a) { F0R(i,SZ) re(a[i]); }
}
namespace output {
template<class T1, class T2> void pr(const pair<T1,T2>& x);
template<class T, size_t SZ> void pr(const array<T,SZ>& x);
template<class T> void pr(const vector<T>& x);
template<class T> void pr(const set<T>& x);
template<class T1, class T2> void pr(const map<T1,T2>& x);
template<class T> void pr(const T& x) { cout << x; }
template<class Arg, class... Args> void pr(const Arg& first, const Args&... rest) {
pr(first); pr(rest...);
}
template<class T1, class T2> void pr(const pair<T1,T2>& x) {
pr("{",x.f,", ",x.s,"}");
}
template<class T> void prContain(const T& x) {
pr("{");
bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; // const needed for vector<bool>
pr("}");
}
template<class T, size_t SZ> void pr(const array<T,SZ>& x) { prContain(x); }
template<class T> void pr(const vector<T>& x) { prContain(x); }
template<class T> void pr(const set<T>& x) { prContain(x); }
template<class T1, class T2> void pr(const map<T1,T2>& x) { prContain(x); }
void ps() { pr("\n"); }
template<class Arg> void ps(const Arg& first) {
pr(first); ps(); // no space at end of line
}
template<class Arg, class... Args> void ps(const Arg& first, const Args&... rest) {
pr(first," "); ps(rest...); // print w/ spaces
}
}
using namespace output;
using namespace input;
ll add(ll a, ll b) {
a += b;
if(a >= MOD) {
a -= MOD;
}
return a;
}
ll sub(ll a, ll b) {
a -= b;
if(a < 0) {
a += MOD;
}
return a;
}
ll mul(ll a, ll b) {
return (a * b)%MOD;
}
void add_self(ll& a, ll b) {
a = add(a, b);
}
void sub_self(ll& a, ll b) {
a = sub(a, b);
}
void mul_self(ll& a, ll b) {
a = mul(a, b);
}
ll N, M;
ll t[4*MX];
ll lazy[4*MX];
void push(ll v) {
t[v*2] += lazy[v];
lazy[v*2] += lazy[v];
t[v*2+1] += lazy[v];
lazy[v*2+1] += lazy[v];
lazy[v] = 0;
}
void update(ll v, ll tl, ll tr, ll l, ll r, ll addend) {
if (l > r)
return;
if (l == tl && tr == r) {
t[v] += addend;
lazy[v] += addend;
} else {
push(v);
ll tm = (tl + tr) / 2;
update(v*2, tl, tm, l, min(r, tm), addend);
update(v*2+1, tm+1, tr, max(l, tm+1), r, addend);
t[v] = max(t[v*2], t[v*2+1]);
}
}
ll query(ll v, ll tl, ll tr, ll l, ll r) {
if (l > r)
return -1e13;
if (l <= tl && tr <= r)
return t[v];
push(v);
ll tm = (tl + tr) / 2;
return max(query(v*2, tl, tm, l, min(r, tm)),
query(v*2+1, tm+1, tr, max(l, tm+1), r));
}
ll prec[MX];
ll pref[MX];
ll prec2[MX];
long long find_shortcut(int n, std::vector<int> l, std::vector<int> d, int c) {
l.insert(l.begin(), 0);
l.insert(l.begin(), 0);
d.insert(d.begin(), 0);
N = n;
FOR (i, 1, N+1) {
pref[i] = pref[i-1]+l[i];
}
ll currbest = pref[N]+d[N];
ROF (i, 1, N) {
prec[i] = max(prec[i+1], currbest-pref[i]+d[i]);
currbest = max(currbest, pref[i]+d[i]);
}
currbest = pref[1]-d[1];
FOR (i, 2, N+1) {
prec2[i] = max(prec2[i-1], pref[i]+d[i]-currbest);
currbest = min(currbest, pref[i]-d[i]);
}
ll ans = prec[1];
ll lbest = 1e13;
FOR (i, 1, N) {
memset(lazy, 0, sizeof(lazy));
memset(t, 0, sizeof(t));
FOR (j, i+1, N+1) {
update(1, 1, N, j, j, pref[j]+d[j]);
}
lbest = min(lbest, pref[i]-d[i]);
update(1, 1, N, i, N, c);
FOR (j, i+1, N+1) {
update(1, 1, N, j, N, -l[j]);
update(1, 1, N, j-1, j-1, pref[j-1]+d[j-1]-query(1, 1, N, j-1, j-1));
ans = min(ans, max({prec2[i], prec[i+1], query(1, 1, N, i+1, N)-lbest}));
}
}
return ans;
}
Compilation message
shortcut.cpp: In function 'void io::setIn(std::__cxx11::string)':
shortcut.cpp:68:35: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
void setIn(string s) { freopen(s.c_str(),"r",stdin); }
~~~~~~~^~~~~~~~~~~~~~~~~~~~~
shortcut.cpp: In function 'void io::setOut(std::__cxx11::string)':
shortcut.cpp:69:36: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
void setOut(string s) { freopen(s.c_str(),"w",stdout); }
~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
512 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
512 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
1 ms |
512 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
1 ms |
512 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
1 ms |
512 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
1 ms |
512 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
1 ms |
512 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
1 ms |
512 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
1 ms |
512 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
1 ms |
512 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
1 ms |
512 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
1 ms |
512 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
1 ms |
512 KB |
n = 3, 3000000000 is a correct answer |
14 |
Incorrect |
1 ms |
512 KB |
n = 4, incorrect answer: jury 3000000001 vs contestant 4000000000 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
512 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
512 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
1 ms |
512 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
1 ms |
512 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
1 ms |
512 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
1 ms |
512 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
1 ms |
512 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
1 ms |
512 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
1 ms |
512 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
1 ms |
512 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
1 ms |
512 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
1 ms |
512 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
1 ms |
512 KB |
n = 3, 3000000000 is a correct answer |
14 |
Incorrect |
1 ms |
512 KB |
n = 4, incorrect answer: jury 3000000001 vs contestant 4000000000 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
512 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
512 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
1 ms |
512 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
1 ms |
512 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
1 ms |
512 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
1 ms |
512 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
1 ms |
512 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
1 ms |
512 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
1 ms |
512 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
1 ms |
512 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
1 ms |
512 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
1 ms |
512 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
1 ms |
512 KB |
n = 3, 3000000000 is a correct answer |
14 |
Incorrect |
1 ms |
512 KB |
n = 4, incorrect answer: jury 3000000001 vs contestant 4000000000 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
512 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
512 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
1 ms |
512 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
1 ms |
512 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
1 ms |
512 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
1 ms |
512 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
1 ms |
512 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
1 ms |
512 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
1 ms |
512 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
1 ms |
512 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
1 ms |
512 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
1 ms |
512 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
1 ms |
512 KB |
n = 3, 3000000000 is a correct answer |
14 |
Incorrect |
1 ms |
512 KB |
n = 4, incorrect answer: jury 3000000001 vs contestant 4000000000 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
512 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
512 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
1 ms |
512 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
1 ms |
512 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
1 ms |
512 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
1 ms |
512 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
1 ms |
512 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
1 ms |
512 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
1 ms |
512 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
1 ms |
512 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
1 ms |
512 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
1 ms |
512 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
1 ms |
512 KB |
n = 3, 3000000000 is a correct answer |
14 |
Incorrect |
1 ms |
512 KB |
n = 4, incorrect answer: jury 3000000001 vs contestant 4000000000 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
512 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
512 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
1 ms |
512 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
1 ms |
512 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
1 ms |
512 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
1 ms |
512 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
1 ms |
512 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
1 ms |
512 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
1 ms |
512 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
1 ms |
512 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
1 ms |
512 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
1 ms |
512 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
1 ms |
512 KB |
n = 3, 3000000000 is a correct answer |
14 |
Incorrect |
1 ms |
512 KB |
n = 4, incorrect answer: jury 3000000001 vs contestant 4000000000 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
512 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
512 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
1 ms |
512 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
1 ms |
512 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
1 ms |
512 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
1 ms |
512 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
1 ms |
512 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
1 ms |
512 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
1 ms |
512 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
1 ms |
512 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
1 ms |
512 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
1 ms |
512 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
1 ms |
512 KB |
n = 3, 3000000000 is a correct answer |
14 |
Incorrect |
1 ms |
512 KB |
n = 4, incorrect answer: jury 3000000001 vs contestant 4000000000 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
512 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
512 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
1 ms |
512 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
1 ms |
512 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
1 ms |
512 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
1 ms |
512 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
1 ms |
512 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
1 ms |
512 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
1 ms |
512 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
1 ms |
512 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
1 ms |
512 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
1 ms |
512 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
1 ms |
512 KB |
n = 3, 3000000000 is a correct answer |
14 |
Incorrect |
1 ms |
512 KB |
n = 4, incorrect answer: jury 3000000001 vs contestant 4000000000 |
15 |
Halted |
0 ms |
0 KB |
- |