Submission #1386736
Source Code Expand
// Nurbakyt Madibek
// Look at my code! IT'S AWESOME
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <ctime>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <cassert>
#include <unordered_map>
#include <bitset>
#include <unordered_set>
using namespace std;
#define pb push_back
#define pp pop_back
#define f first
#define s second
#define mp make_pair
#define sz(a) (int)((a).size())
#ifdef _WIN32
# define I64 "%I64d"
#else
# define I64 "%lld"
#endif
#define fname "."
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < int, int > pi;
typedef pair < int, ull > pu;
typedef pair < ll, ll > pl;
const int inf = (int)1e9 + 123;
const ll infl = (ll)1e18 + 123;
const double eps = 1e-9;
const int MAX_N = (int)1e5 + 5;
const int mod = (int)1e9 + 7;
int n, k;
int a[MAX_N];
ll sum[MAX_N], p[MAX_N];
int main() {
#ifdef DEBUG
freopen("input.txt", "r", stdin);
#endif
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
sum[i] = sum[i - 1] + a[i];
p[i] = p[i - 1] + (a[i] > 0 ? a[i] : 0);
}
ll ans = 0;
for (int i = 1; i + k - 1 <= n; i++)
ans = max(ans, p[i - 1] + p[n] - p[i + k - 1] + (sum[i + k - 1] - sum[i - 1] > 0 ? sum[i + k - 1] - sum[i - 1] : 0));
printf("%lld\n", ans);
return 0;
}
Submission Info
Submission Time |
|
Task |
B - Contiguous Repainting |
User |
Nurbakhyt |
Language |
C++14 (GCC 5.4.1) |
Score |
400 |
Code Size |
1589 Byte |
Status |
AC |
Exec Time |
14 ms |
Memory |
2176 KB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:63:26: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &n, &k);
^
./Main.cpp:65:27: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &a[i]);
^
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 |
10 ms |
2176 KB |
1_04.txt |
AC |
14 ms |
2176 KB |
1_05.txt |
AC |
14 ms |
2176 KB |
1_06.txt |
AC |
14 ms |
2176 KB |
1_07.txt |
AC |
14 ms |
2176 KB |
1_08.txt |
AC |
13 ms |
2176 KB |
1_09.txt |
AC |
14 ms |
2176 KB |
1_10.txt |
AC |
13 ms |
2176 KB |
1_11.txt |
AC |
14 ms |
2176 KB |
1_12.txt |
AC |
13 ms |
2176 KB |
1_13.txt |
AC |
14 ms |
2176 KB |
1_14.txt |
AC |
13 ms |
2176 KB |
1_15.txt |
AC |
14 ms |
2176 KB |
1_16.txt |
AC |
14 ms |
2176 KB |
1_17.txt |
AC |
13 ms |
2176 KB |
1_18.txt |
AC |
14 ms |
2176 KB |
1_19.txt |
AC |
13 ms |
2176 KB |
1_20.txt |
AC |
13 ms |
2176 KB |
1_21.txt |
AC |
13 ms |
2176 KB |