제출 #931083

#제출 시각아이디문제언어결과실행 시간메모리
931083hugsfromadictoStove (JOI18_stove)C++14
100 / 100
18 ms3444 KiB
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int mxN = 1e5+1;
int a[mxN];


void _()
{
    int n,k;
    cin >> n >> k;
    for(int i = 0; i < n; ++i)
        cin >> a[i];
    vector<int>v;
    for(int i = 1; i < n; ++i)
    {
        v.push_back(a[i] - a[i - 1] - 1);
    }
    sort(v.begin(),v.end(),greater<int>());
    int ans = a[n - 1] + 1 - a[0];
    for(int i = 0; i < k - 1; ++i)
        ans -= v[i];
    cout << ans;
}

main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  int tc = 1;
  //cin>>tc;
  while(tc--)
  {
      _();
  }

}


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

stove.cpp:27:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   27 | main()
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...