Submission #1124485

#TimeUsernameProblemLanguageResultExecution timeMemory
1124485PhcKhnhTapCodeStove (JOI18_stove)C++20
100 / 100
21 ms1480 KiB
#include <bits/stdc++.h> /**------------------------------------------ ---------Author: PhcKhnhTapCode ------------- ---------From: CHV with luv ❤ -------------- ---------Training To Win Voi 25 !!! --------- --------------------------------------------- ------------------MemoryLimitExeeded<YAT>-**/ using namespace std; #ifdef phckhnh_local #include "D:\Users\AdminTCT\Desktop\CODE\debug.h" #else #define debug(...) 0 #endif #define ll long long #define db long double #define fi first #define se second #define ii pair<int,int> #define vi vector<int> #define vii vector<ii> #define vvi vector<vi> #define vvvi vector<vvi> #define pub push_back #define all(v) v.begin(),v.end() #define mid(l, r) ((l + r) >> 1LL) #define left(id) (id << 1LL) #define right(id) ((id << 1LL) | 1LL) #define Mask(i) (1LL << (i)) #define Onbit(n, i) (n | Mask(i)) #define Ofbit(n, i) (n ^ Mask(i)) #define Bit(n, i) ((n >> (i)) & 1LL) #define Log2(n) (63 - __builtin_clzll(n)) #define Cntbit(n) __builtin_popcountll(n) #define FOR(i, a, b) for (int i = a; i <= b; ++i) #define FOD(i, b, a) for (int i = b; i >= a; --i) #define rep(i, n) for (int i = 0; i < n; ++i) #define repd(i, n) for (int i = n - 1; ~i;--i) #define repv(v, H) for (auto &v: H) template <class T> bool maximize(T &A, const T &B) {if(A < B) {return A = B, true;} return false;} template <class T> bool minimize(T &A, const T &B) {if(A > B) {return A = B, true;} return false;} const int dx[4] = {0, +1, 0, -1}; const int dy[4] = {+1, 0, -1, 0}; const int inf = 1e9, BLOCK = 700, MAXN = 5e5 + 10; const long long oo = 1e18, BASE = 311, MOD = 1e9 + 7; //____________________________________________________________________ void phckhnh() { int n, k; cin >> n >> k; vi a(n); repv(x, a) cin >> x; int ans = a[n - 1] - a[0] + 1; priority_queue <int> pq; rep(i, n) if(i) pq.push({a[i] - a[i - 1] - 1}); rep(i, k - 1) if(pq.size()) ans -= pq.top(), pq.pop(); cout << ans ; } //____________________________________________________________________ main(){ //____________________________________________________ ios_base :: sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); #define YAT "phckhnh" if (fopen(YAT".inp", "r")) { freopen(YAT".inp", "r", stdin); freopen(YAT".out", "w", stdout); } //____________________________________________________ int Ntest = 1; // cin >> Ntest; while(Ntest--) { phckhnh(); cout << endl; } cerr <<"\nPhcKhnh's TimeRun: " << (1.0 * clock() / CLOCKS_PER_SEC) << "s. \n"; }

Compilation message (stderr)

stove.cpp:76:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   76 | main(){
      | ^~~~
stove.cpp: In function 'int main()':
stove.cpp:82:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   82 |         freopen(YAT".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
stove.cpp:83:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   83 |         freopen(YAT".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...