炼石计划 10 月 06 日 CSP-S 十连测 #3

AisDaeun 4 2023-10-29

#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
using namespace std;
int read() {
	int x = 0; bool fl(0); char ch = getchar();
	while (!isdigit(ch)) fl = ch == '-', ch = getchar();
	while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
	return fl ? -x : x;
}
multiset<int> a;
struct o {int l, r;} b[20010];
signed main() {
	freopen("fly.in", "r", stdin);
	freopen("fly.out", "w", stdout);
	int n = read(), m = read(), ans = 0;
	rep(i, 1, n) a.insert(read());
	rep(i, 1, m) b[i] = {read(), read()};
	sort(b + 1, b + m + 1, [](o &m, o &n) {return m.r < n.r;});
	rep(i, 1, m) {
		auto j = a.lower_bound(b[i].l);
		if (j != a.end() && *j <= b[i].r) ++ans, a.erase(j);
	}
	printf("%d\n", ans);
	return 0;
}

魔法

#include <bits/stdc++.h>
//#define int long long
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
using namespace std;
int read() {
	int x = 0; bool fl(0); char ch = getchar();
	while (!isdigit(ch)) fl = ch == '-', ch = getchar();
	while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
	return fl ? -x : x;
}
const int N = 10010, M = 405, INF = 0x3f3f3f3f;
int a[N], b[N], c[M][M];
signed main() {
	freopen("magic.in", "r", stdin);
	freopen("magic.out", "w", stdout);
	int n = read(), m = read();
	rep(i, 1, n) a[i] = read();
	rep(i, 1, n) b[i] = read();
	memset(c, 0x3f, sizeof c);
	rep(i, 1, 400) c[i][i] = 0;
	rep(i, 1, m) {
		int x = read(), y = read(), z = read();
		c[x][y] = min(c[x][y], z);
	}
	rep(k, 1, 400) rep(i, 1, 400) rep(j, 1, 400) 
		c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
	int ans = 0;
	rep(i, 1, n) {
		int &x = a[i], &y = b[i];
		int tmp = INF;
		rep(j, 1, 400) tmp = min(tmp, c[x][j] + c[y][j]);
		tmp = min({tmp, c[x][y], c[y][x]});
		if (tmp >= INF) {puts(""-1""); return 0;}
		ans += tmp;
	}
	printf("%d\n", ans);
	return 0;
}

地狱疣的新品种

选拔赛