답안 #1094124

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1094124 2024-09-28T13:56:39 Z krishna71701r Stove (JOI18_stove) C++17
100 / 100
19 ms 2916 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];
    read(a, n);
    sort(all(a));
    for(int i =0; i<n-1; i++){
        diff[i] = a[i+1]-a[i]-1;
    }
    sort(rall(diff));
    ll ans = a[n-1]-a[0]+1;
    for(int i = 0;i<k-1; 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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 472 KB Output is correct
12 Correct 1 ms 352 KB Output is correct
13 Correct 1 ms 352 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 472 KB Output is correct
12 Correct 1 ms 352 KB Output is correct
13 Correct 1 ms 352 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 532 KB Output is correct
16 Correct 14 ms 2908 KB Output is correct
17 Correct 14 ms 2788 KB Output is correct
18 Correct 14 ms 2912 KB Output is correct
19 Correct 15 ms 2912 KB Output is correct
20 Correct 15 ms 2912 KB Output is correct
21 Correct 17 ms 2912 KB Output is correct
22 Correct 15 ms 2912 KB Output is correct
23 Correct 15 ms 2912 KB Output is correct
24 Correct 19 ms 2916 KB Output is correct