# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1121039 | Haciyev12 | Stove (JOI18_stove) | C++17 | 1 ms | 336 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "bits/stdc++.h"
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define pb push_back
#define in insert
#define F first
#define S second
#define vll vector<ll>
#define all(v) v.begin(),v.end()
#define endl '\n'
#define pii pair<ll,ll>
using namespace std;
const ll INF =1e18, mod = 1e9 + 7, N = 1e5 + 5;
void solve(){
ll n,m;
cin >> n >> m;
ll xw;
vll v;
for(int i = 0; i < n; i++){
cin >> xw;
v.pb(xw);
}
if(n == m){
cout << n << endl;
return;
}
if(m == 1){
cout << v[v.size() - 1] + 1 - v[0] << endl;
return;
}
ll x = 0;
ll in = -1;
for(int i = 0; i < v.size(); i+=2){//0 1 2 3 4
if(m == 1 && (i + 1 != v.size() || i == v.size() - 1)){
in = i;
break;
}
// cout <<v[i + 1] << " " << v[i] << endl;
x += v[i + 1] + 1 - v[i];
m--;
}
// cout << in <<endl;
if(in != -1){
x += v[v.size() - 1] + 1 - v[in];
}
cout << x << endl;
}
int main(){
fast;
solve();
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |