Submission #854813

# Submission time Handle Problem Language Result Execution time Memory
854813 2023-09-29T03:09:41 Z hungt58 Stove (JOI18_stove) C++14
100 / 100
17 ms 5720 KB
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define ll long long
#define TIME  (1.0 * clock() / CLOCKS_PER_SEC)
typedef pair<ll,ll> ii;
const ll maxn=300010;
ll n,p[maxn],a[maxn];
priority_queue<ii,vector<ii>,greater<ii>> q;
 int root(int i)
{
    if (p[i] == i) return i;
    return root(p[i]);

}
void merge (long i,long j)
{
    p[root(i)]=p[root(j)];
}
ll b[maxn],k;
int main()
{
 
    ios_base :: sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    cin>>n>>k;
    for (ll i=1;i<=n;i++) cin>>a[i];
    sort (a+1,a+n+1);
    for (ll i=1;i<n;i++) b[i]=a[i+1]-a[i];
    ll res=0;
    n--;
    sort (b+1,b+n+1);
    for (ll i=1;i<=n-k+1;i++)
    res=res+b[i];
    res+=k;
    cout<<res;






}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2480 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2480 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 16 ms 5696 KB Output is correct
17 Correct 16 ms 5708 KB Output is correct
18 Correct 15 ms 5468 KB Output is correct
19 Correct 15 ms 5700 KB Output is correct
20 Correct 17 ms 5468 KB Output is correct
21 Correct 16 ms 5468 KB Output is correct
22 Correct 15 ms 5720 KB Output is correct
23 Correct 15 ms 5468 KB Output is correct
24 Correct 16 ms 5700 KB Output is correct