|
NOIP2015 第二天第一题代码保存 [0]
- //#include <iostream>
- #include <fstream>
- using namespace std;
- ifstream cin("stone3.in");
- ofstream cout("stone3.out");
- int a[50002];
- int l, n, k;
- int i, j, t, p, b;
- int main()
- {
- cin >> l >> n >> k;
- t = a[0] = 0;
- for (i = 1; i <= n; ++i)
- {
- cin >> j;
- a[i] = j - t;
- t = j;
- }
- a[n+1] = l - t;
- for (i = 1; i <= k; ++i)
- {
- t = a[0];
- for (j = 1; j <= n; ++j)
- if (t == 0 || (a[j] != 0 && a[j] < t))
- {
- t = a[j];
- p = j;
- }
- if (a[n+1] < t)
- {
- b = n;
- while (a[b] == 0)
- --b;
- a[n+1] += a[b];
- a[b] = 0;
- }
- else
- {
- b = p + 1;
- while (a[b] == 0)
- ++b;
- a[b] += a[p];
- a[p] = 0;
- }
- }
- t = a[0];
- for (j = 1; j <= n+1; ++j)
- if (t == 0 || (a[j] != 0 && a[j] < t))
- t = a[j];
- cout << t;
- return 0;
- }
复制代码 |
|