Submission #1073326

#TimeUsernameProblemLanguageResultExecution timeMemory
1073326RKHTMStove (JOI18_stove)C++14
100 / 100
17 ms3544 KiB
#include <bits/stdc++.h> using namespace std; #define yasuho ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define endl "\n" typedef long long ll; const ll MOD = 1e9+7; /* 1 2 5 6 8 11 13 15 16 20 1 3 1 2 3 2 2 1 4 ^ ^ ^ ^ */ void solve(){ ll n, k; cin >> n >> k; vector<ll> v(n+1); for(int i=1; i<=n; i++) cin >> v[i]; ll ans = v.back()+1-v[1]; vector<ll> u; for(int i=2; i<=n; i++){ u.push_back(v[i]-v[i-1]); } sort(u.begin(), u.end(), greater<ll>()); for(int i=0; i<u.size() and i<k-1; i++){ // cout << u[i] << ' '; ans -= u[i]-1; } cout << ans << endl; return; } int main(){ yasuho // remove for interactive problem ll t; t = 1; //cin >> t; while(t--) solve(); }

Compilation message (stderr)

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