Problem hidden
|This problem was hidden by Editorial Board member probably because it has incorrect language|version or invalid test data, or description of the problem is not clear.|

RGB7588 - Урвуулах тоглоом

Иахуб уйдсандаа цаасан дээр тоглодог тоглоом зохиожээ. Эхлээд n ширхэг a1, a2,...,an тоо бичнэ. Бичсэн тоонууд нь зөвхөн 0 юм уу 1 байна. i,j toog songon avaad (1<=i<=j<=n) [i,j] zavsar dahi buh ai toonuudiig erguulne. x too ni x=1-x bolno. Тоглоомын зорилго бол зөвхөн нэг үйлдэл хийгээд боломжит хамгийн олон нэгүүдийг гаргаж авах юм. Иахубын тоглоомыг шийддэг програм зохионо уу.

Input

The first line of the input contains an integer n (1 ≤ n ≤ 100). In the second line of the input there are n integers: a1, a2, ..., an. It is guaranteed that each of those n values is either 0 or 1.

Output

Print an integer — the maximal number of 1s that can be obtained after exactly one move.

Example

Input 1:

5
1 0 0 1 0

Output 1:

4

Input 2:

4
1 0 0 1

Output 2:

4


Нэмсэн:Bataa
Огноо:2013-02-06
Хугацааны хязгаарлалт:1s
Эх кодын хэмжээний хязгаарлалт:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Програмчлалын хэлүүд:ADA95 ASM32 BASH BF C NCSHARP CSHARP C++ 4.3.2 CPP C99 CLPS LISP sbcl LISP clisp D ERL FORTRAN HASK ICON ICK JAVA JS-RHINO JULIA LUA NEM NICE OCAML PAS-GPC PAS-FPC PERL PHP PIKE PRLG-swi PYTHON PYPY3 PYTHON3 RUBY SCALA SCM guile ST TCL WHITESPACE
Эх сурвалж:Codeforces.com

hide comments
2024-01-19 05:59:24
#include <stdio.h>

int main() {
int n;
scanf("%d", &n);
int a[n];
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}

int result = 0;
for (int i = 0; i < n; i++) {
for (int j = i; j < n; j++) {
int temp[n];
for (int k = 0; k < n; k++) {
temp[k] = a[k];
}

for (int k = i; k <= j; k++) {
temp[k] = 1 - temp[k];
}

int count = 0;
for (int k = 0; k < n; k++) {
if (temp[k] == 1) {
count++;
}
}
result = (result > count) ? result : count;
}
}
printf("%d", result);
return 0;
}
2024-01-15 08:52:00
#include<bits/stdc++.h>
using namespace std;
int main(){
int n, k[101], m[101], l = -1;
int a[101], b[101];
cin >> n;
k[0] = 0;
m[0] = 0;
b[0] = 0;
for(int i = 0; i < n; i++){
cin >> a[i];
}
for(int i = 0; i < n; i++){
if(a[i] == 0){
k[i + 1] = k[i] + 1;
m[i + 1] = m[i];
}else{
k[i + 1] = k[i];
m[i + 1] = m[i] + 1;
}
b[i + 1] = k[i + 1] - m[i + 1];
}
for(int i = 1; i <= n; i++){
for(int j = i; j <= n; j++){
if(b[j] - b[i - 1] > l){
l = b[j] - b[i - 1];
}
}
}
cout << m[n] + l ;
}
2023-12-16 07:19:08
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int a[n],b[n][n],c[n+1],d[n+1],ih=-2;
c[0]=0;
d[0]=0;
for(int i=0; i<n; i++){
cin>>a[i];
if(a[i]==0){
c[i+1]=c[i]+1;
d[i+1]=d[i];
}
else{
d[i+1]=d[i]+1;
c[i+1]=c[i];
}
}
for(int i=0; i<n; i++){
for(int j=i; j<n; j++){
b[i][j]=(c[j+1]-c[i])-(d[j+1]-d[i]);
}
}
for(int i=0; i<n; i++){
for(int j=i; j<n; j++){
if(b[i][j]>ih){
ih=b[i][j];
}
}
}
ih=ih+d[n];
cout<<ih;
}
2023-06-24 05:28:52
Ene deer zaaval neg uildel hiih ystoi shuu. Bugdeeree 1 baisan ch uildel hiih ystoi
2023-02-22 15:21:00
#include<bits/stdc++.h>
using namespace std;

int main() {
int n, a, j, k, result = 0, arr[100], max = 0, maxTemp = 0;

cin >> n;
for(int i = 0; i < n; i++) {
cin >> a;
arr[i] = a;
if(arr[i] == 0) {
maxTemp++;
if(max < maxTemp) {
max = maxTemp;
k = i;
}
} else {
maxTemp = 0;
}
}

j = k - max + 1;

for(int i = j; i <= k; i++) {
arr[i] = 1;
}

maxTemp = 0;

for(int i = 0; i < n; i++) {
if(arr[i] == 1) {
maxTemp++;
if(result < maxTemp) {
result = maxTemp;
}
} else {
maxTemp = 0;
}
}

cout << result;

return 0;
}
uug n ene bolood bhin aldaag n harsan hun bval heleed ogooch(oruulsan toogoo bas bicheed ogvol bayrlan shu) temuujin geed reply hiigeed ogoorei.

Last edit: 2023-02-22 15:21:59
2020-03-28 05:09:57
zaza good luck bros


Last edit: 2020-03-28 05:12:24
2020-02-08 11:17:22
batorgil codeforces hayagiig ni aw huu
2019-03-01 10:13:42
#include <stdio.h>

int main()
{
int arr[10];
int sum,product,i;

/*Read array elements*/
printf("\nEnter elements : \n");
for(i=0; i<10; i++)
{
printf("Enter arr[%d] : ",i);
scanf("%d",&arr[i]);
}

/*calculate sum and product*/
sum=0;
product=1;
for(i=0; i<10; i++)
{
sum=sum+arr[i];
product=product*arr[i];
}

printf("\nSum of array is : %d" ,sum);
printf("\nProduct of array is : %d\n",product);

return 0;
}
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.