/*===================== # Author: Chaos1018 # Blog : chaos1018.ml # Mail : minyuenu@gmail.com ======================*/ #include<bits/stdc++.h> usingnamespace std;
#define Debug(x) cout << #x <<" = " << x << endl #define pii pair <int, int> #define mp make_pair #define fi first #define se second #define pb push_back #define ll long long #define vi vector<int> template <typename T> inlinevoidread(T &a){ T w = 1; a = 0; char ch = getchar(); for(;ch < '0' || ch > '9'; ch = getchar()) if(ch == '-') w = -1; for(;ch >= '0' && ch <= '9'; ch = getchar()) a = (a*10) + (ch-'0'); a *= w; } template <typename T> inlinevoidckmax(T &a,T b){a = a > b ? a : b;} template <typename T> inlinevoidckmin(T &a,T b){a = a < b ? a : b;} constint inf = 2e9; constint MAX = 333; int R, CC, n; pii s[MAX]; int a[MAX]; structValue { int a, b, c; Value (int A = 0, int B = 0, int C = 0) { a = A, b = B, c = C; } } f[MAX][MAX], g[MAX << 1];
vi w;
structQueue { pii q[MAX << 2]; int l, r; inlinevoidInit(){ l = 1, r = 0; } inlinevoiderase(int x){ while (l <= r && q[l].fi < x) l++; } inlinevoidinsert(int x, int y){ while (l <= r && q[r].se <= y) r--; q[++r] = mp(x, y); } ll top(){ return q[l].se; } } A, B, C;
ll pos[MAX << 1], tp[MAX << 1]; ll Ans;
inlinevoidsol(int len){ if (len >= Ans) return ; for (int i = 1; i <= n; ++i) tp[i] = s[i].fi, tp[i + n] = s[i].fi + len + 1; merge (&tp[1], &tp[n + 1], &tp[n + 1], &tp[n + n + 1], &pos[1]); int tot = unique (&pos[1], &pos[n + n + 1]) - pos - 1; // for (int i = 1; i <= tot; ++i) cout << pos[i] << " "; puts(""); for (int i = 1, l = 1, r = 1; i <= tot; ++i) { while (l <= n && ((s[l].fi > pos[i]) || (s[l].fi + len < pos[i]))) l++; ckmax(r, l); while (r <= n && ( (s[r].fi <= pos[i]) && (s[r].fi + len >= pos[i]))) r++; if (l > n) g[i] = Value(inf, inf, inf); else g[i] = f[l][r - 1]; } A.Init(); B.Init(); C.Init(); for (int i = 1, j = 1; i <= tot; ++i) { A.erase(i); B.erase(i); C.erase(i); while (j <= tot && pos[i] + R - 1 >= pos[j]) A.insert(j, g[j].a), B.insert(j, g[j].b), C.insert(j, g[j].c), j++; ll tmp = max(A.top() + B.top(), C.top() ); if (tmp >= inf) return; ckmin(Ans, 1ll * len + tmp); } }
intmain(){ freopen ("cultivation.in", "r", stdin); freopen ("cultivation.out", "w", stdout); read(R); read(CC); read(n); Ans = R + CC; for (int i = 1; i <= n; ++i) read(s[i].fi), read(s[i].se); sort (s + 1, s + n + 1); for (int i = 1; i <= n; ++i) { int m = 0; for (int j = i; j <= n; ++j) { int pos = m; for (int k = 0; k < m; ++k) if (a[k] > s[j].se) { pos = k; break; } for (int k = m; k > pos; --k) a[k] = a[k - 1]; a[pos] = s[j].se; f[i][j].a = a[0] - 1; f[i][j].b = CC - a[m++]; for (int k = 1; k < m; ++k) ckmax(f[i][j].c, a[k] - a[k - 1] - 1); } } w.pb(0); for (int i = 1; i <= n; ++i) w.pb( s[i].fi - 1 ), w.pb(R - s[i].fi); for (int i = 1; i <= n; ++i) for (int j = 1; j < i; ++j) w.pb(max( s[i].fi - s[j].fi - 1, 0) ); for (int i = 1; i <= n; ++i) for (int j = 1; j <= n; ++j) w.pb( R - s[i].fi + s[j].fi - 1 ); sort (w.begin(), w.end()); w.erase (unique(w.begin(), w.end()), w.end()); int siz = w.size(); for (int i = 0; i < siz; ++i) sol (w[i]); printf ("%lld", Ans); return0; }
/*===================== # Author: Chaos1018 # Blog : chaos1018.ml # Mail : minyuenu@gmail.com ======================*/ #include<bits/stdc++.h> usingnamespace std;
#define Debug(x) cout << #x <<" = " << x << endl #define pii pair <int, int> #define pdd pair <double, double> #define mp make_pair #define fi first #define se second #define pb push_back #define db double template <typename T> inlinevoidread(T &a){ T w = 1; a = 0; char ch = getchar(); for(;ch < '0' || ch > '9'; ch = getchar()) if(ch == '-') w = -1; for(;ch >= '0' && ch <= '9'; ch = getchar()) a = (a*10) + (ch-'0'); a *= w; } template <typename T> inlinevoidckmax(T &a,T b){a = a > b ? a : b;} template <typename T> inlinevoidckmin(T &a,T b){a = a < b ? a : b;} constint MAX = 1e5 + 10; const db eps = 1e-18; int n, k, T; int s[MAX];
vector < db > a, b; vector< pdd > A, B; boolcheck(int v){ a.clear(), b.clear(), A.clear(), B.clear(); for (int i = k; i > 1; --i) a.pb(0.5 * (s[i] - s[i - 1]) / v ); for (int i = k; i < n; ++i) b.pb(0.5 * (s[i + 1] - s[i]) / v ); db res = 0, mx = 1e18; // 到达一个点,消耗a_i时间,获得T时间 // res -= a[i], res += T; db last = T; for (int i = 0; i < a.size(); ++i) last -= a[i], last += T; for (int i = 0; i < b.size(); ++i) last -= b[i], last += T; if (last < 0) returnfalse; int tmpa = -1, tmpb = -1; for (int i = 0; i < a.size(); ++i) { res -= a[i]; ckmin(mx, res); res += T; if (res > -eps) A.pb ( mp(-mx, res) ), res = 0, mx = 1e18, tmpa = i; } res = 0, mx = 1e18; for (int i = 0; i < b.size(); ++i) { res -= b[i]; ckmin(mx, res); res += T; if (res > -eps) B.pb ( mp(-mx, res) ), res = 0, mx = 1e18, tmpb = i; } res = T; int x = 0, y = 0; while ( x < A.size() || y < B.size() ) { if (x < A.size() && res >= A[x].fi ) res += A[x++].se; elseif (y < B.size() && res >= B[y].fi ) res += B[y++].se; elsereturnfalse; } A.clear(), B.clear(); res = 0, mx = 1e18; for (int i = a.size() - 1; i > tmpa; --i) { res -= T; ckmin(mx, res); res += a[i]; if (res > -eps) A.pb ( mp (-mx, res) ), res = 0, mx = 1e18; } res = 0, mx = 1e18; for (int i = b.size() - 1; i > tmpb; --i) { res -= T; ckmin(mx, res); res += b[i]; if (res > -eps) B.pb ( mp (-mx, res) ), res = 0, mx = 1e18; } res = last; x = 0, y = 0; while ( x < A.size() || y < B.size() ) { if (x < A.size() && res >= A[x].fi) res += A[x++].se; elseif (y < B.size() && res >= B[y].fi) res += B[y++].se; elsereturnfalse; } returntrue; }
intmain(){ freopen ("sparklers.in", "r", stdin); freopen ("sparklers.out", "w", stdout); int flag = 0; read(n); read(k); read(T); for (int i = 1; i <= n; ++i) { read(s[i]); if (s[i] != s[i - 1]) flag = 1; } if (!flag) returnputs("0"), 0; int l = 1, r = 1e9 + 10; while (l < r) { int mid = l + r >> 1; if ( check (mid) ) r = mid; else l = mid + 1; } printf ("%d\n", l); return0; }