# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
41526 | chonka | Stove (JOI18_stove) | C++98 | 43 ms | 1804 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std ;
#define MAXN 100007
int n , k ;
int a[ MAXN ] ;
int b[ MAXN ] ;
int ans ;
void input ( ) {
scanf ( "%d%d" , &n , &k ) ;
int i ;
for ( i = 1 ; i <= n ; i ++ ) {
scanf ( "%d" , &a[ i ] ) ;
}
ans = n ;
}
void solve ( ) {
int i ;
for ( i = 1 ; i < n ; i ++ ) {
b[ i ] = ( a[ i + 1 ] - a[ i ] - 1 ) ;
}
sort ( b + 1 , b + n ) ;
for ( i = 1 ; i <= ( n - k ) ; i ++ ) {
ans += b[ i ] ;
}
printf ( "%d\n" , ans ) ;
}
int main ( ) {
input ( ) ;
solve ( ) ;
return 0 ;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |