Submission #481430

#TimeUsernameProblemLanguageResultExecution timeMemory
481430VovamatrixStove (JOI18_stove)C++14
100 / 100
24 ms5452 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define mp make_pair #define mt make_tuple #define fi first #define sc second #define th third #define fo fourth #define pii pair<int,int> #define pll pair<ll,ll> #define ldb double #define endl "\n" #define MAXN 100007 ll a[MAXN]; vector<ll> v; int main() { ios::sync_with_stdio(false); cin.tie(0); int n,k; cin>>n>>k; for(int i=0;i<n;i++) { cin>>a[i]; if(i==0) v.pb(a[i]); else if(a[i]-a[i-1]>1) { v.pb(a[i-1]+1); v.pb(a[i]); } if(i==n-1) v.pb(a[i]+1); } int x=v.size()/2-k; ll rez=0; //cout<<x<<endl; //for(auto q:v) cout<<q<<" ";cout<<endl; for(int i=0;i<v.size()-1;i=i+2) { rez+=v[i+1]-v[i]; } //cout<<rez<<endl; if(x<=0) cout<<rez; else { vector<ll> v1; for(int i=2;i<v.size()-1;i=i+2) { v1.pb(v[i]-v[i-1]); } sort(v1.begin(),v1.end()); //for(auto q:v1) cout<<q<<" "; //cout<<endl; for(int i=0;i<x;i++) rez+=v1[i]; cout<<rez; } return 0; }

Compilation message (stderr)

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