제출 #756871

#제출 시각아이디문제언어결과실행 시간메모리
756871Niko_shmikoGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
0 / 100
1 ms212 KiB
#include<bits/stdc++.h>
using namespace std;

int n, i, j, ans, k;

int main(){
    scanf("%d", &n);
    int a[n];
    for(i=0; i<n; i++){
        scanf("%d", &a[i]);
        if(i>0){
            a[i-1]=a[i]-a[i-1];
        }
    }
    i=0;
    j=n-2;
    while(i<j){
        if(a[i]>0){
            i++;
            continue;
        }
        if(a[j]<0){
            j--;
            continue;
        }
        k=min(1-a[i], 1+a[j]);
        a[i]+=k;
        a[j]-=k;
        ans+=k;
    }
    if(a[i]==0){
        ans++;
    }
    printf("%d", ans);
}

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp: In function 'int main()':
Main.cpp:7:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    7 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
Main.cpp:10:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |         scanf("%d", &a[i]);
      |         ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...