0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-27 14:36:27 +00:00

Compare commits

..

No commits in common. "552f6e3464c62b3c8624b48b051a63a06f1ca942" and "d22fe79fff91a9082d50cb17caa7c747a1955594" have entirely different histories.

2 changed files with 0 additions and 114 deletions

View File

@ -1,56 +0,0 @@
#include <iostream>
#include <algorithm>
#include <numeric>
#include <utility>
#include <vector>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 3e5 + 5;
int n, k;
std::pair<int, int> a[N];
std::vector<int> nums;
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> a[i].first >> a[i].second;
nums.emplace_back(a[i].first);
}
std::sort(a + 1, a + 1 + n, [](std::pair<int, int> x, std::pair<int, int> y) { return x.first < y.first; });
std::sort(nums.begin(), nums.end());
nums.erase(std::unique(nums.begin(), nums.end()), nums.end());
for (int i = 1; i <= n; i++) {
a[i].first = std::lower_bound(nums.begin(), nums.end(), a[i].first) - nums.begin() + 1;
}
long long sum = std::accumulate(a + 1, a + 1 + n, 0ll, [](long long x, std::pair<int, int> y) { return x + y.second; });
if (sum <= k) {
cout << 1 << endl;
exit(0);
}
for (int i = 1; i <= n; i++) {
sum -= a[i].second;
if (sum <= k) {
cout << nums[a[i].first - 1] + 1 << endl;
exit(0);
}
}
return 0;
}

View File

@ -1,58 +0,0 @@
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 3e5 + 5;
int n1, n2, m, dist1[N], dist2[N];
bool vis[N];
std::vector<int> g[N];
void bfs(int s, int* dist) {
std::queue<int> q;
q.emplace(s);
vis[s] = true;
while (!q.empty()) {
int u = q.front();
q.pop();
for (int v : g[u]) {
if (vis[v]) continue;
vis[v] = true;
dist[v] = dist[u] + 1;
q.emplace(v);
}
}
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n1 >> n2 >> m;
for (int i = 1, u, v; i <= m; i++) {
cin >> u >> v;
g[u].emplace_back(v);
g[v].emplace_back(u);
}
bfs(1, dist1);
bfs(n1 + n2, dist2);
cout << *std::max_element(dist1 + 1, dist1 + 1 + n1)
+ *std::max_element(dist2 + n1 + 1, dist2 + n1 + n2 + 1) + 1
<< endl;
return 0;
}