Submission #33142014
Source Code Expand
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=500007;
int a[N],b[N],g[N][2],f[N][2],n,k,ans;
bool chk(int x){
for(int i=1;i<=n;i++)b[i]=a[i]+x;
memset(f,-63,sizeof(f)),memset(g,0,sizeof(g));
f[0][0]=0;
for(int i=1;i<=n;i++){
if(f[i-1][0]>f[i-1][1])f[i][0]=f[i-1][0],g[i][0]=g[i-1][0];
else f[i][0]=f[i-1][1],g[i][0]=g[i-1][1];
f[i][1]=f[i-1][0]+b[i],g[i][1]=g[i-1][0]+1;
}
ans=max(f[n][0],f[n][1])-x*k;
int t=f[n][0]>f[n][1]?g[n][0]:g[n][1];
return t>=k;
}
int la;
signed main(){
scanf("%lld%lld",&n,&k);
k=min(k,n-k);
for(int i=1,x;i<n;i++){
scanf("%lld",&x);
a[i]=x+la;
la=x;
}
a[n]=la;
int l=-1e12,r=1e12;
while(l+1<r){
int mid=l+r>>1;
if(chk(mid))r=mid;
else l=mid;
}
if(chk(l))printf("%lld",ans);
else chk(r),printf("%lld",ans);
}
Submission Info
| Submission Time |
|
| Task |
H - Red and Blue Lamps |
| User |
houzhiyuan |
| Language |
C++ (GCC 9.2.1) |
| Score |
600 |
| Code Size |
888 Byte |
| Status |
AC |
| Exec Time |
118 ms |
| Memory |
22400 KiB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:31:15: warning: suggest parentheses around ‘+’ inside ‘>>’ [-Wparentheses]
31 | int mid=l+r>>1;
| ~^~
./Main.cpp:21:10: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
21 | scanf("%lld%lld",&n,&k);
| ~~~~~^~~~~~~~~~~~~~~~~~
./Main.cpp:24:14: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
24 | scanf("%lld",&x);
| ~~~~~^~~~~~~~~~~
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
600 / 600 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
sample_01.txt, sample_02.txt, sample_03.txt |
| All |
hand_01.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, sample_01.txt, sample_02.txt, sample_03.txt |
| Case Name |
Status |
Exec Time |
Memory |
| hand_01.txt |
AC |
52 ms |
19136 KiB |
| random_01.txt |
AC |
65 ms |
20304 KiB |
| random_02.txt |
AC |
69 ms |
19956 KiB |
| random_03.txt |
AC |
92 ms |
21160 KiB |
| random_04.txt |
AC |
65 ms |
20060 KiB |
| random_05.txt |
AC |
69 ms |
20256 KiB |
| random_06.txt |
AC |
64 ms |
19976 KiB |
| random_07.txt |
AC |
101 ms |
22216 KiB |
| random_08.txt |
AC |
118 ms |
22240 KiB |
| random_09.txt |
AC |
50 ms |
19360 KiB |
| random_10.txt |
AC |
108 ms |
21800 KiB |
| random_11.txt |
AC |
93 ms |
22368 KiB |
| random_12.txt |
AC |
113 ms |
22300 KiB |
| random_13.txt |
AC |
101 ms |
22400 KiB |
| random_14.txt |
AC |
98 ms |
22264 KiB |
| random_15.txt |
AC |
115 ms |
22332 KiB |
| random_16.txt |
AC |
94 ms |
22352 KiB |
| random_17.txt |
AC |
87 ms |
22300 KiB |
| random_18.txt |
AC |
83 ms |
22332 KiB |
| random_19.txt |
AC |
94 ms |
22352 KiB |
| random_20.txt |
AC |
98 ms |
22400 KiB |
| random_21.txt |
AC |
84 ms |
21900 KiB |
| random_22.txt |
AC |
95 ms |
21900 KiB |
| random_23.txt |
AC |
83 ms |
21780 KiB |
| random_24.txt |
AC |
80 ms |
21804 KiB |
| sample_01.txt |
AC |
43 ms |
19208 KiB |
| sample_02.txt |
AC |
45 ms |
19240 KiB |
| sample_03.txt |
AC |
49 ms |
19256 KiB |