# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1093298 |
2024-09-26T14:03:17 Z |
Lakshya108 |
Stove (JOI18_stove) |
C++14 |
|
1 ms |
348 KB |
// https://oj.uz/problem/view/JOI18_stove
// OI\JOI-Stove.pdf
#include <bits/stdc++.h>
using namespace std;
// Macros
#define pb push_back
#define pf push_front
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
// #define rep(i, x, n) for(int i = x; i < n; ++i)
// #define rrep(i, x, n) for(int i = x; i >= n; --i)
// Read and Print
#define read(a, n) for(ll i = 0; i < n; ++i) cin >> a[i];
#define print(a, n) for(ll i = 0; i < n; ++i){ cout << a[i] << " ";} cout << "\n";
#define endl "\n"
#define sp " "
// Typedefs
typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pii;
typedef vector <ll> vi;
typedef vector <vector <ll>> vvi;
using vec = vector<int>;
// Constants
const ll mxn = 1e6 + 5;
const ll mod = 1e9 + 7;
// Solve
void solve() {
int n, k; cin>>n>>k;
vi a(n);
vi diff(n-1);
cin>>a[0];
for(int i = 1; i<n; i++){
cin>>a[i];
diff[i-1]=abs(a[i]-a[i-1]);
}
sort(all(diff));
sort(all(a));
ll ans = a[n-1]-a[0]+1;
if(k==n) ans = n;
else if(k!=1){
for(int i = 0;i<k; i++){
if(diff[i]>0) ans-=diff[i];
}
}
cout<<ans<<endl;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |