The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | May 2017 |
| Last Sign in: | 406 Weeks Ago, 2 Days Ago |
| Questions Answered: | 66690 |
| Tutorials Posted: | 66688 |
MCS,PHD
Argosy University/ Phoniex University/
Nov-2005 - Oct-2011
Professor
Phoniex University
Oct-2001 - Nov-2016
1. Description
N people are waiting in line to enter a concert. People get bored waiting so they turn and
look for someone familiar in the line. Two persons A and B standing in line can see each
other if they’re standing right next to each other or if no person between them is strictly
taller than person A or person B. Write a program that determines the number of pairs of
people that can see each other.
Input Format:
The first line of input contains an integer N (1 = N = 500000), the number of people
standing in line. Each of the following N lines contains a single integer, the height of one
person in nanometres. Everyone will be shorter than 231 nanometres. The heights are given
in the order in which people are standing in line.
Output Format:
Output the number of pairs of people that can see each other on a single line.
Constraints 1 = N = 500000, Height Sample Input :
7
2
4
1
2
2
5
1
4.5
Sample Output:
10
2. Description:
A histogram is a polygon composed of a sequence of rectangles aligned at a common base
line. The rectangles have equal widths but may have different heights. Calculate the area of
the largest rectangle in a histogram that is aligned at the common base line, too.
Input Format:
The input contains several test cases. Each test case describes a histogram and starts with an
integer n, denoting the number of rectangles it is composed of. You may assume that 1 = n =
100000. Then follow n integers h1 , . . . hn , where 0 = hi = 1000000000. These numbers
denote the heights of the rectangles of the histogram in left-to-right order. The width of each
rectangle is 1. A zero follows the input for the last test case.
Output Format:
For each test case output on a single line the area of the largest rectangle in the specified
histogram. Remember that this rectangle must be aligned at the common base line.
Sample Input :
72145133
4 1000 1000 1000 1000
0
Sample Output:
8
4000
Hel-----------lo -----------Sir-----------/Ma-----------dam-----------Tha-----------nk -----------You----------- fo-----------r u-----------sin-----------g o-----------ur -----------web-----------sit-----------e a-----------nd -----------and----------- ac-----------qui-----------sit-----------ion----------- of----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n.P-----------lea-----------se -----------pin-----------g m-----------e o-----------n c-----------hat----------- I -----------am -----------onl-----------ine----------- or----------- in-----------box----------- me----------- a -----------mes-----------sag-----------e I----------- wi-----------ll