답안 #335880

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
335880 2020-12-14T07:48:00 Z Killer2501 Stove (JOI18_stove) C++14
100 / 100
33 ms 7916 KB
#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define pll pair<ll, ll>
#define pb push_back
#define pii pair<ll ,pll>
#define task "C"

using namespace std;
const int N = 2e5+5;
const int M = 4e6+5;
const int mod = 1e9+7;
ll n, t, m, k, a[N], ans, tong, h[N], u, v;

string s;
bool ok;
vector<ll> adj[N], kq;
vector<pll> res;
struct dang
{
    ll x, y, h;
}e[N], f[N];
bool cmp(const dang& u, const dang& v)
{
    return u.h < v.h;
}
void sol()
{
    cin >> n >> m;
    for(int i = 1; i <= n; i ++)cin >> a[i];
    sort(a+1, a+1+n);
    priority_queue<ll> pq;
    for(int i = 2; i <= n; i ++)pq.push(a[i]-a[i-1]-1);
    ans = a[n] - a[1] + 1;
    while(m > 1)
    {
        ans -= pq.top();
        pq.pop();
        --m;
    }
    cout << ans;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    if(fopen(task".inp", "r"))
    {
        freopen(task".inp", "r", stdin);
        freopen(task".out", "w", stdout);
    }
    sol();
}

Compilation message

stove.cpp: In function 'int main()':
stove.cpp:51:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   51 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
stove.cpp:52:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   52 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5100 KB Output is correct
2 Correct 4 ms 5100 KB Output is correct
3 Correct 4 ms 5100 KB Output is correct
4 Correct 4 ms 5100 KB Output is correct
5 Correct 4 ms 5100 KB Output is correct
6 Correct 4 ms 5100 KB Output is correct
7 Correct 4 ms 5100 KB Output is correct
8 Correct 4 ms 5100 KB Output is correct
9 Correct 4 ms 5100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5100 KB Output is correct
2 Correct 4 ms 5100 KB Output is correct
3 Correct 4 ms 5100 KB Output is correct
4 Correct 4 ms 5100 KB Output is correct
5 Correct 4 ms 5100 KB Output is correct
6 Correct 4 ms 5100 KB Output is correct
7 Correct 4 ms 5100 KB Output is correct
8 Correct 4 ms 5100 KB Output is correct
9 Correct 4 ms 5100 KB Output is correct
10 Correct 4 ms 5228 KB Output is correct
11 Correct 4 ms 5228 KB Output is correct
12 Correct 5 ms 5248 KB Output is correct
13 Correct 6 ms 5228 KB Output is correct
14 Correct 5 ms 5228 KB Output is correct
15 Correct 4 ms 5228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5100 KB Output is correct
2 Correct 4 ms 5100 KB Output is correct
3 Correct 4 ms 5100 KB Output is correct
4 Correct 4 ms 5100 KB Output is correct
5 Correct 4 ms 5100 KB Output is correct
6 Correct 4 ms 5100 KB Output is correct
7 Correct 4 ms 5100 KB Output is correct
8 Correct 4 ms 5100 KB Output is correct
9 Correct 4 ms 5100 KB Output is correct
10 Correct 4 ms 5228 KB Output is correct
11 Correct 4 ms 5228 KB Output is correct
12 Correct 5 ms 5248 KB Output is correct
13 Correct 6 ms 5228 KB Output is correct
14 Correct 5 ms 5228 KB Output is correct
15 Correct 4 ms 5228 KB Output is correct
16 Correct 20 ms 7916 KB Output is correct
17 Correct 20 ms 7916 KB Output is correct
18 Correct 20 ms 7916 KB Output is correct
19 Correct 24 ms 7916 KB Output is correct
20 Correct 26 ms 7916 KB Output is correct
21 Correct 32 ms 7916 KB Output is correct
22 Correct 32 ms 7916 KB Output is correct
23 Correct 33 ms 7916 KB Output is correct
24 Correct 33 ms 7916 KB Output is correct