Submission #197349

#TimeUsernameProblemLanguageResultExecution timeMemory
197349abilStove (JOI18_stove)C++14
100 / 100
28 ms2356 KiB
# include <bits/stdc++.h> # define fr first # define sc second # define pb push_back # define sz(s) s.size() # define all(s) s.begin(),s.end() //# define int long long using namespace std; const long long N = (1e6 + 10); const long long mod = (1e9 + 7); const long long inf = (1e9 + 7); int a[N]; main() { int n, k; cin >> n >> k; vector<int > vec; for(int i = 1;i <= n; i++){ scanf("%d", &a[i]); } for(int i = 2;i <= n; i++){ vec.pb(max((a[i]) - (a[i - 1] + 1),0)); } sort(all(vec)); k--; int ans = a[n] + 1 - a[1]; for(int i = vec.size() - 1;i >= 0; i--){ if(!k){ break; } k--; ans -= vec[i]; } cout << ans; }

Compilation message (stderr)

stove.cpp:18:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main()
      ^
stove.cpp: In function 'int main()':
stove.cpp:24:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &a[i]);
   ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...