A. Insert
模拟
代码实现
n, k, x = map(int, input().split())
a = list(map(int, input().split()))
a.insert(k, x)
print(*a)
B. Intersection of Cuboids
模拟
代码实现
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
struct Point {
int x, y, z;
};
Point input() {
Point p;
cin >> p.x >> p.y >> p.z;
return p;
}
bool solve() {
Point l1 = input();
Point r1 = input();
Point l2 = input();
Point r2 = input();
rep(i, 2) {
if (r1.x <= l2.x) return false;
if (r1.y <= l2.y) return false;
if (r1.z <= l2.z) return false;
swap(l1, l2);
swap(r1, r2);
}
return true;
}
int main() {
if (solve()) puts("Yes");
else puts("No");
return 0;
}
C. Make Them Narrow
对序列 \(A\) 做一遍升序排序,然后遍历所有大小为 \(n-k\) 的窗口即可
代码实现
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
int main() {
int n, k;
cin >> n >> k;
vector<int> a(n);
rep(i, n) cin >> a[i];
sort(a.begin(), a.end());
int ans = 1e9;
rep(l, k+1) {
int r = l+(n-k)-1;
int now = a[r] - a[l];
ans = min(ans, now);
}
cout << ans << '\n';
return 0;
}