알고리즘/Codeforces

R621(Div.1+Div.2) A. Cow and Haybales

세진짱 2020. 2. 19. 10:25

 

처음에 문제 이해를 잘못했다

문제는 첫번째칸에 가장 큰 수를 만들라는 문제다

그럼 거리를 보고 만약 다른칸에 수가 0이 아니라면 그만큼 옴기면 된다!

 

소스코드

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
using namespace std;
int arr[111];
int ans;
 
int main() {
    int t; scanf(" %d"&t);
    while (t--) {
        memset(arr, 0sizeof(arr));
        int n, m; scanf(" %d %d"&n, &m); ans = 0;
        for (int i = 0; i < n; i++scanf(" %d"&arr[i]);
        for (int i = 1; i < n; i++) {
            if (!arr[i]) continue;
            while (m >= i && arr[i]) {
                arr[i]--;
                ans +=1 ; m -= i;
            }
        }
        printf("%d\n", ans+arr[0]);
    }
}