Submission #1219893
Source Code Expand
#include <iostream> #include <stdio.h> #include <vector> #include <string.h> #include <algorithm> #define int long long using namespace std; const int N=123456; int a[N]; int bj[N]; vector <int> u; signed main() { int n,k; scanf("%lld %lld",&n,&k); int koo=0; for(int i=0; i<n; i++) { scanf("%lld",a+i); koo+=a[i]; } memset(bj,0,sizeof(bj)); for(int i=0; i<n; i++) { if(a[i]>0){ if(bj[i]==0) { if(i+k<=n) { for(int j=i;j<i+k;j++) { bj[j]=1; } } else { break; } } } else { if(bj[i]==1) { if(i+k<=n) { for(int j=i;j<i+k;j++) { bj[j]=0; } } else { break; } } } } int sum=0; for(int i=0; i<n; i++) { if(bj[i]) sum+=a[i]; } for(int i=0;i<n;i++) { int uo=0; int h=0; while(a[i]<=0 && i<n) { h++; uo+=a[i]; i++; } if(h>=k) { u.push_back(-uo); } } if(!u.empty()) { sort(u.begin(),u.end()); int p=u.size(); printf("%lld\n",max(sum,koo+u[p-1])); return 0; } printf("%lld\n",sum); return 0; }
Submission Info
Submission Time | |
---|---|
Task | B - Contiguous Repainting |
User | hanssy |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 1514 Byte |
Status | WA |
Exec Time | 442 ms |
Memory | 2432 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:18:29: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%lld %lld",&n,&k); ^ ./Main.cpp:21:26: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%lld",a+i); ^
Judge Result
Set Name | Sample | All | ||||||
---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 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 | 2 ms | 1152 KB |
0_01.txt | AC | 2 ms | 1152 KB |
0_02.txt | AC | 2 ms | 1152 KB |
0_03.txt | AC | 2 ms | 1152 KB |
1_00.txt | AC | 2 ms | 1152 KB |
1_01.txt | AC | 2 ms | 1152 KB |
1_02.txt | AC | 2 ms | 1152 KB |
1_03.txt | AC | 10 ms | 2048 KB |
1_04.txt | AC | 15 ms | 2048 KB |
1_05.txt | AC | 14 ms | 2048 KB |
1_06.txt | AC | 15 ms | 2432 KB |
1_07.txt | AC | 16 ms | 2304 KB |
1_08.txt | AC | 13 ms | 1920 KB |
1_09.txt | AC | 14 ms | 1920 KB |
1_10.txt | WA | 20 ms | 1920 KB |
1_11.txt | WA | 442 ms | 1920 KB |
1_12.txt | WA | 77 ms | 1920 KB |
1_13.txt | WA | 411 ms | 2048 KB |
1_14.txt | WA | 60 ms | 1920 KB |
1_15.txt | WA | 318 ms | 1920 KB |
1_16.txt | WA | 440 ms | 2048 KB |
1_17.txt | WA | 103 ms | 2048 KB |
1_18.txt | WA | 430 ms | 1920 KB |
1_19.txt | WA | 87 ms | 1920 KB |
1_20.txt | WA | 395 ms | 1920 KB |
1_21.txt | WA | 215 ms | 2048 KB |