Submission #41526

#TimeUsernameProblemLanguageResultExecution timeMemory
41526chonkaStove (JOI18_stove)C++98
100 / 100
43 ms1804 KiB
#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)

stove.cpp: In function 'void input()':
stove.cpp:16:32: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf ( "%d%d" , &n , &k ) ;
                                ^
stove.cpp:19:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf ( "%d" , &a[ i ] ) ;
                                  ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...