0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2025-01-23 09:31:59 +00:00

#128. 【2020.11.26 NOIP模拟赛 T2】等差数列

https://sjzezoj.com/submission/17705
This commit is contained in:
Baoshuo Ren 2021-08-16 17:05:42 +08:00 committed by Baoshuo Ren
parent 37c2368a5b
commit b82ff6f591
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

30
S2OJ/128/128.cpp Normal file
View File

@ -0,0 +1,30 @@
#include <bits/stdc++.h>
using namespace std;
int n, w, a[300005], t[3000005], ans;
int main() {
cin >> n >> w;
if (n == 1) {
cout << 0 << endl;
exit(0);
}
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int d = 0; (n - 1) * d <= w; d++) {
for (int i = 0; i < n; i++) {
if (a[i] > d * i && a[i] + (n - i + 1) * d <= w) {
ans = max(ans, ++t[a[i] - d * i]);
}
}
for (int i = 0; i < n; i++) {
if (a[i] > d * i) {
t[a[i] - d * i] = 0;
}
}
}
cout << n - ans << endl;
return 0;
}