bzoj2091

来源:互联网 发布:怎么提高英语听力知乎 编辑:程序博客网 时间:2024/06/06 02:05

这题真妙

#include<bits/stdc++.h>using namespace std;inline int read(void) {    int x = 0, c = 0, f = 1;    for (; c<'0' || c>'9'; c = getchar()) f = c !='-';    for (; c >='0' && c <= '9'; c = getchar()) x = x * 10 + c - '0';    return f ? x : -x;}const int N = 1010000;int f[N],a[N],n;int main() {    n = read();    for (int i = 1; i <= n; i++) a[i] = read();    sort(a+1,a+n+1);    int l = 1, r = 1, now = a[1];    for (int i = 1; i <= n; i++) {        f[i] = now;        now = max(now, a[i + 1] - f[i]);    }     cout << f[n] << endl;}
原创粉丝点击