Submission #41146

#TimeUsernameProblemLanguageResultExecution timeMemory
41146prateepStove (JOI18_stove)C++11
100 / 100
34 ms2144 KiB
#pragma comment(linker,"/STACK:36777216") //#pragma GCC optimize("Ofast") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #include <iostream> #include <cstdio> #include <cmath> #include <cstring> #include <cstdlib> #include <cctype> #include <algorithm> #include <iterator> #include <map> #include <vector> #include <list> #include <set> #include <queue> #include <cassert> #include <deque> #include <stack> #include <bitset> #include <functional> #include <numeric> #include <utility> #include <sstream> #include <iomanip> #include <cstring> #include <cmath> #include <ctime> #include <climits> #include <stdexcept> #include <cfloat> using namespace std; #define LET(x,a) ::typeid(a) x(a) #define IFOR(i,a,b) for(LET(i,a);i!=(b);++i) #define EACH(it,v) IFOR(it,v.begin(),v.end()) #define FOR(i,a,b) for(int i = (a); i < int(b);i++) #define REP(i,n) FOR(i,0,n) #define SZ size() #define PB push_back #define PF push_front #define V(x) vector< x > #define two(X) (1<<(X)) #define twoL(X) (((int64)(1))<<(X)) #define contain(S,X) (((S)&two(X))!=0) #define containL(S,X) (((S)&twoL(X))!=0 #define swap(x,y) x ^=y ^= x^=y #define ALL(v) (v).begin(),(v).end() #define DBN1(a) cerr<<#a<<"="<<(a)<<"\n" const double pi = acos(-1.0); const double eps = 1e-11; const int oo = 0x3f3f3f3f; template<class T> inline void checkmin(T &a, T b){ if (b<a) a = b; } template<class T> inline void checkmax(T &a, T b){ if (b>a) a = b; } template<class T> inline T sqr(T x){ return x*x; } typedef pair<int, int> ipair; template<class T> inline T lowbit(T n){ return (n ^ (n - 1))&n; } template<class T> inline int countbit(T n){ return (n == 0) ? 0 : (1 + countbit(n&(n - 1))); } template<class T> inline T gcd(T a, T b) { T c; while (a != 0) { c = a; a = b%a; b = c; } return b; } template<class T> inline T mabs(T a) { if (a < 0) return -a; else return a; } typedef V(int) VI; typedef V(VI) VII; typedef V(string) VS; typedef long long int64; typedef long double LD; typedef pair<int, int> PI; typedef pair<double, double> PD; const int N = (int) 1e5+111; const int MOD = (int) 1e9+7; int64 a[N], d[N]; inline int solve(int testnum) { int n,k; scanf("%d%d",&n,&k); REP(i,n) { scanf("%lld",&a[i]); if(i > 0) d[i] = a[i] - a[i-1]; else d[0] = oo; } int64 big = a[n-1] - a[0] + k; sort(d+1,d+n,greater<int64>()); for(int i = 1; i <= min(k-1, n-1); i++) { big -= d[i]; } printf("%lld\n", big); return 0; } int main(int argc, char* argv[]) { #ifdef LocalHost freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios::sync_with_stdio(false); int t = 1; //scanf("%d", &t); if (argc > 1) t = atoi(argv[1]); FOR(_t, 1, t + 1) { int ret = ::solve(_t); if (ret == -1) { // cerr << "Failed test #" << _t << endl; break; } //cerr << "Solved test #" << _t << endl; } #ifdef LocalHost printf("Time taken : %.10f seconds\n", (1.0f*clock()) / CLOCKS_PER_SEC); #endif return 0; }

Compilation message (stderr)

stove.cpp:1:0: warning: ignoring #pragma comment  [-Wunknown-pragmas]
 #pragma comment(linker,"/STACK:36777216")
 ^
stove.cpp: In function 'int solve(int)':
stove.cpp:78:33: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     int n,k; scanf("%d%d",&n,&k);
                                 ^
stove.cpp:80:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld",&a[i]);
                      ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...