Submission #574677

#TimeUsernameProblemLanguageResultExecution timeMemory
574677Valters07Stove (JOI18_stove)C++14
100 / 100
24 ms2264 KiB
#include <bits/stdc++.h> #pragma GCC optimize("O2,unroll-loops") #define fio ios_base::sync_with_stdio(0);cin.tie(0); #define ll long long #define en cin.close();return 0; #define pb push_back #define fi first//printf("%lli\n",cur); #define se second//scanf("%lli",&n); #define r0 return 0; using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int main() { fio //ifstream cin("in.in"); int n, k; cin >> n >> k; vector<int> tim(n); for(auto &x:tim) cin >> x; sort(tim.begin(),tim.end()); int ans = tim.back()-tim[0]+1; vector<int> dif; for(int i = 1;i<tim.size();i++) dif.pb(tim[i]-tim[i-1]-1); sort(dif.begin(),dif.end(),greater<int>()); for(int i = 0;i<k-1;i++) ans-=dif[i]; cout << ans; //cin.close(); return 0; }

Compilation message (stderr)

stove.cpp: In function 'int main()':
stove.cpp:24:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |     for(int i = 1;i<tim.size();i++)
      |                   ~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...