mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-27 14:36:27 +00:00
Compare commits
3 Commits
a0a0b5d506
...
bacfa27ddb
Author | SHA1 | Date | |
---|---|---|---|
bacfa27ddb | |||
b07ef359ca | |||
ef580a25a7 |
38
Luogu/P3076/P3076.cpp
Normal file
38
Luogu/P3076/P3076.cpp
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
|
using std::cin;
|
||||||
|
using std::cout;
|
||||||
|
const char endl = '\n';
|
||||||
|
|
||||||
|
const int N = 1e5 + 5;
|
||||||
|
|
||||||
|
int n, m, x[N], y[N];
|
||||||
|
long long ans;
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
std::ios::sync_with_stdio(false);
|
||||||
|
cin.tie(nullptr);
|
||||||
|
|
||||||
|
cin >> n >> m;
|
||||||
|
|
||||||
|
x[0] = m;
|
||||||
|
|
||||||
|
for (int i = 1; i <= n; i++) {
|
||||||
|
cin >> x[i] >> y[i];
|
||||||
|
|
||||||
|
ans += std::abs(x[i] - y[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::sort(x, x + 1 + n);
|
||||||
|
std::sort(y, y + 1 + n);
|
||||||
|
|
||||||
|
for (int i = 0; i <= n; i++) {
|
||||||
|
ans += std::abs(x[i] - y[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << ans << endl;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
72
Luogu/P3112/P3112.cpp
Normal file
72
Luogu/P3112/P3112.cpp
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <limits>
|
||||||
|
#include <tuple>
|
||||||
|
|
||||||
|
using std::cin;
|
||||||
|
using std::cout;
|
||||||
|
const char endl = '\n';
|
||||||
|
|
||||||
|
const int N = 25;
|
||||||
|
|
||||||
|
int n, h, ans = -1;
|
||||||
|
std::tuple<int, int, int> a[N];
|
||||||
|
bool vis[N];
|
||||||
|
|
||||||
|
void dfs(int x) {
|
||||||
|
if (x == n + 1) {
|
||||||
|
int hh = 0, ss = std::numeric_limits<int>::max();
|
||||||
|
|
||||||
|
for (int i = 1; i <= n; i++) {
|
||||||
|
if (!vis[i]) continue;
|
||||||
|
|
||||||
|
hh += std::get<0>(a[i]);
|
||||||
|
|
||||||
|
int sum = 0;
|
||||||
|
|
||||||
|
for (int j = i + 1; j <= n; j++) {
|
||||||
|
if (!vis[j]) continue;
|
||||||
|
|
||||||
|
sum += std::get<1>(a[j]);
|
||||||
|
}
|
||||||
|
|
||||||
|
ss = std::min(ss, std::get<2>(a[i]) - sum);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hh >= h) {
|
||||||
|
ans = std::max(ans, ss);
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
dfs(x + 1);
|
||||||
|
vis[x] = true;
|
||||||
|
dfs(x + 1);
|
||||||
|
vis[x] = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
std::ios::sync_with_stdio(false);
|
||||||
|
cin.tie(nullptr);
|
||||||
|
|
||||||
|
cin >> n >> h;
|
||||||
|
|
||||||
|
for (int i = 1; i <= n; i++) {
|
||||||
|
cin >> std::get<0>(a[i]) >> std::get<1>(a[i]) >> std::get<2>(a[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::sort(a + 1, a + 1 + n, [&](decltype(a[0]) x, decltype(a[0]) y) -> bool {
|
||||||
|
return std::get<1>(x) + std::get<2>(x) > std::get<1>(y) + std::get<2>(y);
|
||||||
|
});
|
||||||
|
|
||||||
|
dfs(0);
|
||||||
|
|
||||||
|
if (ans == -1) {
|
||||||
|
cout << "Mark is too tall" << endl;
|
||||||
|
} else {
|
||||||
|
cout << ans << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
BIN
Luogu/P3112/data/1.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P3112/data/1.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P3112/data/1.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P3112/data/1.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P3112/data/10.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P3112/data/10.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P3112/data/10.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P3112/data/10.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P3112/data/11.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P3112/data/11.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P3112/data/11.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P3112/data/11.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P3112/data/12.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P3112/data/12.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P3112/data/12.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P3112/data/12.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P3112/data/13.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P3112/data/13.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P3112/data/13.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P3112/data/13.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P3112/data/14.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P3112/data/14.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P3112/data/14.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P3112/data/14.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P3112/data/2.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P3112/data/2.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P3112/data/2.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P3112/data/2.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P3112/data/3.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P3112/data/3.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P3112/data/3.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P3112/data/3.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P3112/data/4.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P3112/data/4.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P3112/data/4.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P3112/data/4.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P3112/data/5.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P3112/data/5.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P3112/data/5.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P3112/data/5.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P3112/data/6.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P3112/data/6.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P3112/data/6.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P3112/data/6.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P3112/data/7.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P3112/data/7.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P3112/data/7.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P3112/data/7.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P3112/data/8.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P3112/data/8.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P3112/data/8.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P3112/data/8.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P3112/data/9.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P3112/data/9.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P3112/data/9.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P3112/data/9.out
(Stored with Git LFS)
Normal file
Binary file not shown.
74
Luogu/P3957/P3957.cpp
Normal file
74
Luogu/P3957/P3957.cpp
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <deque>
|
||||||
|
#include <limits>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
using std::cin;
|
||||||
|
using std::cout;
|
||||||
|
const char endl = '\n';
|
||||||
|
|
||||||
|
const int N = 5e5 + 5;
|
||||||
|
const long long INF = 0x3f3f3f3f3f3f3f3f;
|
||||||
|
|
||||||
|
int n, d;
|
||||||
|
long long k, f[N], sum;
|
||||||
|
std::pair<long long, long long> a[N];
|
||||||
|
|
||||||
|
bool check(long long l, long long r) {
|
||||||
|
std::deque<long long> q;
|
||||||
|
|
||||||
|
for (int i = 1, j = 0; i <= n; i++) {
|
||||||
|
f[i] = -INF;
|
||||||
|
|
||||||
|
while (j < i && l <= a[i].first - a[j].first) {
|
||||||
|
if (f[j] != -INF) {
|
||||||
|
while (!q.empty() && f[q.back()] <= f[j]) q.pop_back();
|
||||||
|
q.push_back(j);
|
||||||
|
}
|
||||||
|
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (!q.empty() && a[i].first - a[q.front()].first > r) {
|
||||||
|
q.pop_front();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!q.empty()) {
|
||||||
|
f[i] = std::max(f[i], f[q.front()] + a[i].second);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (f[i] >= k) return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
std::ios::sync_with_stdio(false);
|
||||||
|
cin.tie(nullptr);
|
||||||
|
|
||||||
|
cin >> n >> d >> k;
|
||||||
|
|
||||||
|
for (int i = 1; i <= n; i++) {
|
||||||
|
cin >> a[i].first >> a[i].second;
|
||||||
|
|
||||||
|
sum += a[i].second;
|
||||||
|
}
|
||||||
|
|
||||||
|
long long l = 0, r = INF;
|
||||||
|
|
||||||
|
while (l < r) {
|
||||||
|
long long mid = l + r >> 1;
|
||||||
|
|
||||||
|
if (check(std::max(d - mid, 0ll), d + mid)) {
|
||||||
|
r = mid;
|
||||||
|
} else {
|
||||||
|
l = mid + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << (r == INF ? -1 : r) << endl;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
BIN
Luogu/P3957/data/P3957_1.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P3957/data/P3957_1.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P3957/data/P3957_1.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P3957/data/P3957_1.out
(Stored with Git LFS)
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user