Submission #757597

# Submission time Handle Problem Language Result Execution time Memory
757597 2023-06-13T12:14:11 Z franz123ferdinand Stove (JOI18_stove) C++14
100 / 100
25 ms 4356 KB
#include <bits/stdc++.h>

using namespace std;
#define int long long
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
   int n,m,ans = 0;
   cin>>n>>m;
   m--;
   int a[n];
   vector <pair<int,int>> b(n-1);
   int bs[n-1];
  cin>>a[0];
  for(int k=1;k<n;k++){
        cin>>a[k];
        b[k-1].first = a[k] - a[k-1];
        bs[k-1] = b[k-1].first;
  }
  if(n==1){
      cout<<1;
      return 0;
   }
  sort(bs,bs+n-1);
  int cnt = 0;
  for(int k=0;k<n-1;k++){
        if(b[k].first>=bs[n-m-1] and n-m-1<=n-2) {
              cnt++;
              b[k].second = 1;
        } else b[k].second = 0;
  }
  if(cnt>m){
        for(int k=0;k<n-1;k++){
              if(b[k].first==bs[n-m-1] and cnt>m){
                    b[k].second = 0;
                    cnt--;
              }
        }
  }
  for(int k=0;k<n-1;k++){
        int j = k;
        if(b[k].second==1) ans++; else {
              while(b[j].second!=1 and j<n-1){
              ans = ans + b[j].first;
              j++;
        }
        ans++;
        k = j;
        }
  }
  if(b[n-2].second==1) ans++;
  cout<<ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 21 ms 4328 KB Output is correct
17 Correct 20 ms 4336 KB Output is correct
18 Correct 25 ms 4344 KB Output is correct
19 Correct 20 ms 4344 KB Output is correct
20 Correct 21 ms 4340 KB Output is correct
21 Correct 19 ms 4356 KB Output is correct
22 Correct 19 ms 4340 KB Output is correct
23 Correct 19 ms 4296 KB Output is correct
24 Correct 19 ms 4300 KB Output is correct