https://www.nowcoder.com/acm/contest/96/H
坑点:INF开太小了。。。
#define _CRT_SECURE_NO_WARNINGS #include<cstring> #include<cctype> #include<cmath> #include<cstdio> #include<string> #include<stack> #include<ctime> #include<list> #include<set> #include<map> #include<queue> #include<vector> #include<sstream> #include<iostream> #include<algorithm> //#define INF 0x3f3f3f3f #define eps 1e-6 #define pi acos(-1.0) #define e exp(1.0) #define fre(i,t,n) for(int i =(t);i<=(n);++i) #define fer(i,n,t) for(int i =(n);i>=(t);--i) #define mp make_pair #define pb push_back //std::ios::sync_with_stdio(false); using namespace std; typedef long long ll; typedef unsigned long long ull; void smain(); #define ONLINE_JUDGE int main() { ios::sync_with_stdio(false); #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); long _begin_time = clock(); #endif smain(); #ifndef ONLINE_JUDGE long _end_time = clock(); printf("time = %ld ms.", _end_time - _begin_time); #endif return 0; } const int maxn = 2e5 + +100; const int mod = 1e9 + 7; const ll INF= (100000)*(200000ll) + 1000; ll a[maxn], b[maxn], mx[maxn]; void Run() { fre(i, 0, maxn) mx[i] = -INF; int n, k; cin >> n >> k; fre(i, 1, n)cin >> a[i]; fre(i, 1, n) a[i] += a[i - 1]; fre(i, k, n)b[i] = a[i] - a[i - k]; fre(i, k, n)mx[i] = max(mx[i - 1], b[i]); ll ans = -INF; fre(i, 2 * k, n) { ans = max(ans, mx[i - k] + b[i]); } cout << ans ; } void smain() { int t; cin >> t; while (t--) { Run(); cout << endl; } }