제출 #1017864

#제출 시각아이디문제언어결과실행 시간메모리
1017864vjudge1Stove (JOI18_stove)C++17
100 / 100
45 ms3136 KiB
#include <bits/stdc++.h> #define int long long #define Aiko ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); #define pb push_back using namespace std; const int INF=1e18; signed main(){ int n, i, k, j, ans1=0, mn=0, mx=-INF, ans3=0; cin>>n>>k; int a[n+1]; int ans[n+1]; int sum[n+1]; for(i=1;i<=n;i++){ cin>>a[i]; } if(k==1)cout<<a[n]+1-a[1]; else if(n<=k)cout<<n; else{ sum[0]=0; vector<int>v; for(i=1;i<n;i++){ v.pb(a[i+1]-a[i]-1); } int ans11=a[n]-a[1]+1; sort(v.begin(),v.end()); reverse(v.begin(),v.end()); for(i=0;i<k-1;i++){ ans11-=v[i]; } cout<<ans11; } }

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

stove.cpp: In function 'int main()':
stove.cpp:9:18: warning: unused variable 'j' [-Wunused-variable]
    9 |     int n, i, k, j, ans1=0, mn=0, mx=-INF, ans3=0;
      |                  ^
stove.cpp:9:21: warning: unused variable 'ans1' [-Wunused-variable]
    9 |     int n, i, k, j, ans1=0, mn=0, mx=-INF, ans3=0;
      |                     ^~~~
stove.cpp:9:29: warning: unused variable 'mn' [-Wunused-variable]
    9 |     int n, i, k, j, ans1=0, mn=0, mx=-INF, ans3=0;
      |                             ^~
stove.cpp:9:35: warning: unused variable 'mx' [-Wunused-variable]
    9 |     int n, i, k, j, ans1=0, mn=0, mx=-INF, ans3=0;
      |                                   ^~
stove.cpp:9:44: warning: unused variable 'ans3' [-Wunused-variable]
    9 |     int n, i, k, j, ans1=0, mn=0, mx=-INF, ans3=0;
      |                                            ^~~~
stove.cpp:12:9: warning: unused variable 'ans' [-Wunused-variable]
   12 |     int ans[n+1];
      |         ^~~
stove.cpp:13:9: warning: variable 'sum' set but not used [-Wunused-but-set-variable]
   13 |     int sum[n+1];
      |         ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...