Submission #208736

# Submission time Handle Problem Language Result Execution time Memory
208736 2020-03-12T05:57:03 Z tushar_2658 Stove (JOI18_stove) C++14
100 / 100
34 ms 3312 KB
#include "bits/stdc++.h"
using namespace std;

const int maxn = 100005;
using ll = long long;

ll a[maxn];

int main(int argc, char const *argv[])
{
//  freopen("in.txt", "r", stdin);
  int n, k;
  scanf("%d %d", &n, &k);
  for(int i = 1; i <= n; i++){
    scanf("%lld", &a[i]);
  }
  sort(a + 1, a + n + 1); 
  vector<ll> v;
  for(int i = 2; i <= n; i++){
    v.push_back(a[i] - a[i - 1]);
  }
  sort(v.begin(), v.end(), greater<ll>());
  ll ans = 0;
  int cnt = 0;
  for(int i = 0; i < (int)v.size(); i++){
    if(i < k - 1){
      ans++;
    }else {
      ans += v[i];
    }
  }
  cout << ans + 1 << endl;

  return 0;
}

Compilation message

stove.cpp: In function 'int main(int, const char**)':
stove.cpp:24:7: warning: unused variable 'cnt' [-Wunused-variable]
   int cnt = 0;
       ^~~
stove.cpp:13:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &n, &k);
   ~~~~~^~~~~~~~~~~~~~~~~
stove.cpp:15:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld", &a[i]);
     ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 6 ms 256 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
6 Correct 5 ms 248 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 6 ms 256 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
6 Correct 5 ms 248 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 248 KB Output is correct
10 Correct 6 ms 376 KB Output is correct
11 Correct 6 ms 376 KB Output is correct
12 Correct 6 ms 376 KB Output is correct
13 Correct 6 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 6 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 6 ms 256 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
6 Correct 5 ms 248 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 248 KB Output is correct
10 Correct 6 ms 376 KB Output is correct
11 Correct 6 ms 376 KB Output is correct
12 Correct 6 ms 376 KB Output is correct
13 Correct 6 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 6 ms 376 KB Output is correct
16 Correct 34 ms 3184 KB Output is correct
17 Correct 32 ms 3312 KB Output is correct
18 Correct 32 ms 3184 KB Output is correct
19 Correct 32 ms 3184 KB Output is correct
20 Correct 32 ms 3312 KB Output is correct
21 Correct 32 ms 3184 KB Output is correct
22 Correct 32 ms 3184 KB Output is correct
23 Correct 34 ms 3184 KB Output is correct
24 Correct 32 ms 3184 KB Output is correct