루미 알고리즘

#1392플래티넘Cookies

PO 2016 훈련 캠프코딩출제 Johan Sannemo영어 원문이 문제가 어렵다면 — 배우는 순서 보기

영어 원문입니다. 원문의 수식·표를 글자로 옮겨 모양이 다를 수 있습니다. 정확한 내용은 원문 페이지에서 확인하세요. 원문 페이지 열기 (새 창)

Problem

Ann Britt-Caroline has N different types of cookies. She has A_i cookies of type i. Now, Ann is wondering how many cookies she has in total.

Example

In this example, we have N = 3 different types of cookies. The number of cookies of each type is 3, 1, 5.

(그림은 원문 저장소에서 볼 수 있습니다)

Figure 1: We have three cookies of the first kind, one of the second kind, and five of the third

As pictured, this gives a total of 9 different cookies.

Task

You will be given N and A. Write a program to help Ann compute the total number of cookies. You should implement the function cookies(N, A):

• cookies(N, A) - this function will be called exactly once by the judge.

  • N: the number of types of cookies.
  • A: a vector of length N. A[i] (0 ≤ i < N) contains the number of cookies of type i. A[i] is always positive.
  • The function should return the number of cookies Ann has.

A code skeleton containing the function to be implemented, together with a sample grader, can be found at http://progolymp.se/uploads/kattis-attachments/kakor.zip.

Subtasks

The problem consists of a number of subtasks. Each subtask gives some amount of points, and to pass the subtask you must pass all the test cases in the subtask.

SubtaskPointsLimits
1271 ≤ N ≤ 1000, A[i] = 1.
2341 ≤ N ≤ 1000, A[i] ≤ 100000.
3391 ≤ N ≤ 100000, A[i] ≤ 100000.

Input format

The sample judge reads input in the following format:

  • line 1: N
  • line 2: A[0] A[1] ... A[N - 1]

Output format

The sample judge writes the return value of cookies(A, N).

예제

예제 1

입력
3
3 1 5
출력
9

출처 표기

출처: Programmeringsolympiaden 2016년 훈련 캠프 · 원문 페이지 · 이용 조건 CC BY-SA · LaTeX 원문을 화면용 글로 옮겼습니다(수식·표의 모양이 다를 수 있습니다). 내용은 고치지 않았습니다.

크리에이티브 커먼즈 저작자표시-동일조건변경허락.

문제 출처: 한국정보올림피아드(KOI) (CC BY-NC-SA 4.0) · International Olympiad in Informatics (IOI) (CC BY) · Centre for Education in Mathematics and Computing (CEMC), University of Waterloo (CC BY-NC 4.0) · Programmeringsolympiaden (CC BY-SA) · CSES Problem Set (Antti Laaksonen) (CC BY-NC-SA 4.0). 루미 알고리즘은 위 단체들과 관계없는 별도의 서비스이며, 자료는 원문 그대로 싣습니다. 문제마다 출처와 이용 조건을 따로 표기합니다.