Submission #1694721
Source Code Expand
#include <algorithm> #include <bitset> #include <complex> #include <deque> #include <exception> #include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <new> #include <numeric> #include <ostream> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <streambuf> #include <string> #include <typeinfo> #include <utility> #include <valarray> #include <vector> #define REP(i, m, n) for(int i=int(m);i<int(n);i++) #define EACH(i, c) for (auto &(i): c) #define all(c) begin(c),end(c) #define EXIST(s, e) ((s).find(e)!=(s).end()) #define SORT(c) sort(begin(c),end(c)) #define pb emplace_back #define MP make_pair #define SZ(a) int((a).size()) //#define LOCAL 0 //#ifdef LOCAL //#define DEBUG(s) cout << (s) << endl //#define dump(x) cerr << #x << " = " << (x) << endl //#define BR cout << endl; //#else //#define DEBUG(s) do{}while(0) //#define dump(x) do{}while(0) //#define BR //#endif //改造 typedef long long int ll; using namespace std; #define INF (1 << 20) #define INFl (ll)5e15 #define DEBUG 0 //デバッグする時1にしてね //ここから編集する int main() { int N, K; cin >> N >> K; vector<ll> a(N), b(N); vector<ll> acc_a(N + 1, 0), acc_b(N + 1, 0); REP(i, 0, N) { cin >> a[i]; b[i] = max(0LL, a[i]); } //K個の連続する0以上や0以下を調べる REP(i, 0, N) { acc_a[i + 1] = acc_a[i] + a[i]; acc_b[i + 1] = acc_b[i] + b[i]; } //a[x] ~ a[y] の累積和 is acc_a[y+1] - acc_a[x] ll ans = 0; REP(i,K,N+1){ //acc_a[i - K] ~ acc_a[i-1]は塗りつぶすやつ //acc_b[0] ~ acc_b[i-K-1] と acc_b[i] ~ acc_b[N-1]までのWA ll sub1 = max(acc_a[i] - acc_a[i-K],0LL); ll sub2 = (acc_b[i-K] - acc_b[0]) + (acc_b[N] - acc_b[i]); ans = max(ans,sub1 + sub2); } cout << ans << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | B - Contiguous Repainting |
User | homesentinel |
Language | C++14 (GCC 5.4.1) |
Score | 400 |
Code Size | 2183 Byte |
Status | AC |
Exec Time | 49 ms |
Memory | 3328 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 400 / 400 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt |
All | 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt, 1_14.txt, 1_15.txt, 1_16.txt, 1_17.txt, 1_18.txt, 1_19.txt, 1_20.txt, 1_21.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
0_00.txt | AC | 1 ms | 256 KB |
0_01.txt | AC | 1 ms | 256 KB |
0_02.txt | AC | 1 ms | 256 KB |
0_03.txt | AC | 1 ms | 256 KB |
1_00.txt | AC | 1 ms | 256 KB |
1_01.txt | AC | 1 ms | 256 KB |
1_02.txt | AC | 1 ms | 256 KB |
1_03.txt | AC | 19 ms | 3328 KB |
1_04.txt | AC | 45 ms | 3328 KB |
1_05.txt | AC | 49 ms | 3328 KB |
1_06.txt | AC | 42 ms | 3328 KB |
1_07.txt | AC | 43 ms | 3328 KB |
1_08.txt | AC | 44 ms | 3328 KB |
1_09.txt | AC | 43 ms | 3328 KB |
1_10.txt | AC | 43 ms | 3328 KB |
1_11.txt | AC | 44 ms | 3328 KB |
1_12.txt | AC | 44 ms | 3328 KB |
1_13.txt | AC | 43 ms | 3328 KB |
1_14.txt | AC | 42 ms | 3328 KB |
1_15.txt | AC | 44 ms | 3328 KB |
1_16.txt | AC | 43 ms | 3328 KB |
1_17.txt | AC | 42 ms | 3328 KB |
1_18.txt | AC | 44 ms | 3328 KB |
1_19.txt | AC | 41 ms | 3328 KB |
1_20.txt | AC | 43 ms | 3328 KB |
1_21.txt | AC | 43 ms | 3328 KB |