Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
二分最好用 long long(紫书上是 double)int 会爆掉 #include <cstdio> #include <algorithm> #define int long long int n, f; int a[100050]; inline bool Check(int val) { int foo = 0; int ans = -1; static int buf[100050]; for (int i = 1; i <= n; ++i) { buf[i] = buf[i - 1] + a[i] - val; } for (int i = f; i <= n; ++i) { if (buf[i - f] < foo) foo = buf[i - f]; if (buf[i] - foo > ans) ans = buf[i] - foo; } return ans >= 0; } signed main() { scanf("%lld%lld", &n, &f); for (int i = 1; i <= n; ++i) { scanf("%lld", &a[i]); a[i] *= 1000; } int l = a[1], r = a[1]; for (int i = 1; i <= n; ++i) { if (a[i] < l) l = a[i]; else if (a[i] > r) r = a[i]; } while (l < r) { int mid = (l + r + 1) >> 1; if (Check(mid)) l = mid; else r = mid - 1; } printf("%lld\n", l); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator