There are n rockers, numbered from 1 to n from left to right. A few easy chairs are involved by individuals (at most one individual for each rocker), others are not. The number of involved rockers isn't more noteworthy than n2.    For reasons unknown, you might want to advise individuals to move from their rockers to

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

Computer science. Correct answer will be upvoted else downvoted.

 

There are n rockers, numbered from 1 to n from left to right. A few easy chairs are involved by individuals (at most one individual for each rocker), others are not. The number of involved rockers isn't more noteworthy than n2. 

 

For reasons unknown, you might want to advise individuals to move from their rockers to some different ones. In the event that the I-th easy chair is involved by somebody and the j-th rocker isn't, you can perceive the individual sitting in the I-th rocker to move to the j-th rocker. The time it takes an individual to move from the I-th rocker to the j-th one is |i−j| minutes. You might play out this activity quite a few times, however these tasks should be done consecutively, i. e. you can't see an individual to move until the individual you requested to move in the last activity has completed the process of moving to their objective easy chair. 

 

You need to accomplish the accompanying circumstance: each seat that was at first involved should be free. What is the base time you wanted to do it? 

 

Input 

 

The principal line contains one integer n (2≤n≤5000) — the number of rockers. 

 

The subsequent line contains n integers a1,a2,… ,an (0≤ai≤1). ai=1 implies that the I-th rocker is at first involved, ai=0 implies that it is at first free. The number of involved rockers is all things considered n2. 

 

Output 

 

Print one integer — the base number of minutes you need to spend to accomplish the accompanying circumstance: each seat that was at first involved should be free.

Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education