Problem - B - Codeforces
题意:
思路:
直接枚举是去掉哪个店,然后计算贡献即可
虽然赛时做出来了,但是这种计算还是感觉不熟练
Code:
#include <bits/stdc++.h>
#define int long long
using i64 = long long;
constexpr int N = 2e5 + 10;
constexpr int mod = 998244353;
int n, m, d;
int a[N];
int calc(int l, int r) {
return (a[r] - a[l]) / d + ((a[r] - a[l]) % d != 0);
}
void solve() {
std::cin >> n >> m >> d;
for (int i = 1; i <= m; i ++) {
std::cin >> a[i];
}
a[0] = 1;
a[m + 1] = n + 1;
int sum = 0;
int st = 0;
if (a[1] == 1) st = 1;
for (int i = st; i <= m; i ++) {
sum += calc(i, i + 1);
}
int res = sum;
std::vector<int> ans;
int mi = 1e9;
for (int i = 1; i <= m; i ++) {
res = sum;
res += calc(i - 1, i + 1) - (calc(i - 1, i) + calc(i, i + 1));
mi = std::min(mi, res);
}
int cnt = 0;
for (int i = 1; i <= m; i ++) {
res = sum;
res += calc(i - 1, i + 1) - (calc(i - 1, i) + calc(i, i + 1));
if (mi == res) cnt ++;
}
std::cout << mi << " " << cnt << "\n";
}
signed main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t = 1;
std::cin >> t;
while (t--) {
solve();
}
return 0;
}