시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 128 MB 130 41 32 37.209%

문제

수열의 값이란 수열에서 가장 큰 원소와 가장 작은 원소의 차이이다.

예를 들어, (3, 1, 7, 2)는 수열의 값이 6이고, (42, 42)는 0이다.

수열이 주어졌을 때, 모든 부분 수열의 값의 합을 출력하는 프로그램을 작성하시오 .

(3, 1, 7, 2)의 부분 수열은 총 10개 (3), (1), (7), (2), (3,1), (1,7), (7,2), (3,1,7), (1,7,2), (3,1,7,2) 가 있고, 각각의 수열의 값을 구한뒤 이를 합하면 31이 된다.

입력

첫째 줄에 수열의 크기 N(2<=N<=300,000)이 주어진다. 둘째 줄부터 N개의 줄에는 수열의 원소가 한 줄에 하나씩 주어진다. 원소는 100,000,000보다 크지 않은 양의 정수이다.

출력

첫째 줄에 입력으로 주어진 수열의 부분 수열의 값의 합을 출력한다.

예제 입력 1

3
1
2
3

예제 출력 1

4
W3sicHJvYmxlbV9pZCI6IjI4NjciLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJcdWMyMThcdWM1ZjRcdWM3NTggXHVhYzEyIiwiZGVzY3JpcHRpb24iOiI8cD5cdWMyMThcdWM1ZjRcdWM3NTggXHVhYzEyXHVjNzc0XHViNzgwIFx1YzIxOFx1YzVmNFx1YzVkMFx1YzExYyBcdWFjMDBcdWM3YTUgXHVkMDcwIFx1YzZkMFx1YzE4Y1x1YzY0MCBcdWFjMDBcdWM3YTUgXHVjNzkxXHVjNzQwIFx1YzZkMFx1YzE4Y1x1Yzc1OCBcdWNjMjhcdWM3NzRcdWM3NzRcdWIyZTQuPFwvcD5cclxuXHJcblxyXG5cclxuPHA+XHVjNjA4XHViOTdjIFx1YjRlNFx1YzViNCwgKDMsIDEsIDcsIDIpXHViMjk0IFx1YzIxOFx1YzVmNFx1Yzc1OCBcdWFjMTJcdWM3NzQgNlx1Yzc3NFx1YWNlMCwgKDQyLCA0MilcdWIyOTQgMFx1Yzc3NFx1YjJlNC48XC9wPl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sZXN0IG51bWJlciB3aXRoaW4gdGhhdCBzZXF1ZW5jZS4gRm9yIGV4YW1wbGUsIHZhbHVlIG9mIHNlcXVlbmNlICgzLCAxLCA3LCAyKSBpcyA2LCBhbmQgdmFsdWUgb2YgKDQyLCA0MikgaXMgMC4mbmJzcDs8XC9wPlxyXG5cclxuPHA+RmluZCB0aGUgc3VtIG9mIHZhbHVlcyBvZiBhbGwgc3Vic2VxdWVuY2VzIG9mIGNvbnNlY3V0aXZlIGVsZW1lbnRzIG9mIGEgZ2l2ZW4gc2VxdWVuY2UuJm5ic3A7PFwvcD5cclxuIiwiaW5wdXQiOiI8cD5UaGUgZmlyc3QgbGluZSBvZiBpbnB1dCBjb250YWlucyBhIHNpbmdsZSBpbnRlZ2VyIE4gKDIgJmxlOyBOICZsZTsgMzAwIDAwMCksIG51bWJlciBvZiBlbGVtZW50cyBvZiB0aGUgc2VxdWVuY2UuJm5ic3A7PFwvcD5cclxuXHJcbjxwPk5leHQgTiBsaW5lcyBjb250YWluIGVsZW1lbnRzIG9mIHRoZSBzZXF1ZW5jZS4gRWFjaCBlbGVtZW50IGlzIGEgcG9zaXRpdmUgaW50ZWdlciBub3QgZ3JlYXRlciB0aGFuIDEwMCAwMDAgMDAwLiZuYnNwOzxcL3A+XHJcbiIsIm91dHB1dCI6IjxwPlRoZSBmaXJzdCBhbmQgb25seSBsaW5lIG9mIG91dHB1dCBtdXN0IGNvbnRhaW4gdGhlIHJlcXVlc3RlZCBzdW0uJm5ic3A7PFwvcD5cclxuXHJcbjxwPiZuYnNwOzxcL3A+XHJcbiIsImhpbnQiOiIiLCJvcmlnaW5hbCI6IjEiLCJwcm9ibGVtX2xhbmdfY29kZSI6Ilx1YzYwMVx1YzViNCJ9XQ==

출처

Contest > Croatian Open Competition in Informatics > COCI 2010/2011 > Contest #3 5번

  • 잘못된 조건을 찾은 사람: august14
  • 문제를 번역한 사람: baekjoon