标签:nlog sum har org onclick family gis ros build
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 11175 | Accepted: 3666 |
Description
Input
Output
Sample Input
10 6 6 4 2 10 3 8 5 9 4 1
Sample Output
6500
Source
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cstdlib> 5 #include <cmath> 6 7 inline void read(long long &x) 8 { 9 x = 0;char ch = getchar(),c = ch; 10 while(ch < ‘0‘ || ch > ‘9‘)c = ch, ch = getchar(); 11 while(ch <= ‘9‘ && ch >= ‘0‘)x = x * 10 + ch - ‘0‘, ch = getchar(); 12 if(c == ‘-‘)x = -x; 13 } 14 15 const int MAXN = 100000 + 10; 16 17 long long n,num[MAXN],len,sum,tmp[MAXN],dp[MAXN]; 18 19 int check(long long m) 20 { 21 for(register int i = 1;i <= n;++ i) 22 tmp[i] = num[i] - m; 23 //dp[i]表示从i开始向右的最大和 24 for(register int i = n;i >= 1;-- i) 25 if(dp[i + 1] + tmp[i] > 0)dp[i] = dp[i + 1] + tmp[i]; 26 else dp[i] = 0; 27 for(register int i = 1;i <= n;++ i) 28 tmp[i] += tmp[i - 1]; 29 //最短长度len + 向右最大和 30 for(register int i = len;i <= n;++ i) 31 if(tmp[i] - tmp[i - len] + dp[i + 1] >= 0) 32 return 1; 33 return 0; 34 } 35 36 int main() 37 { 38 read(n), read(len); 39 for(register int i = 1;i <= n;++ i) 40 read(num[i]), num[i] *= 10000000, sum += num[i]; 41 register long long l = 1, r = sum, mid, ans; 42 while(l <= r) 43 { 44 mid = (l + r) >> 1; 45 if(check(mid)) l = mid + 1; 46 else r = mid - 1; 47 } 48 printf("%lld", l/10000); 49 return 0; 50 }
标签:nlog sum har org onclick family gis ros build
原文地址:http://www.cnblogs.com/huibixiaoxing/p/7294891.html