From b82ff6f591a08d2334b960fc85f4acff5b4a6f0d Mon Sep 17 00:00:00 2001 From: Ren Baoshuo Date: Mon, 16 Aug 2021 17:05:42 +0800 Subject: [PATCH] =?UTF-8?q?#128.=20=E3=80=902020.11.26=20NOIP=E6=A8=A1?= =?UTF-8?q?=E6=8B=9F=E8=B5=9B=20T2=E3=80=91=E7=AD=89=E5=B7=AE=E6=95=B0?= =?UTF-8?q?=E5=88=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://sjzezoj.com/submission/17705 --- S2OJ/128/128.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 S2OJ/128/128.cpp diff --git a/S2OJ/128/128.cpp b/S2OJ/128/128.cpp new file mode 100644 index 00000000..0ba18d86 --- /dev/null +++ b/S2OJ/128/128.cpp @@ -0,0 +1,30 @@ +#include + +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; +}