Submission #542882

#TimeUsernameProblemLanguageResultExecution timeMemory
542882Aldas25Stove (JOI18_stove)C++14
100 / 100
19 ms2708 KiB
/* //#pragma GCC target ("avx2") #pragma GCC optimize ("O3") #pragma GCC optimize ("unroll-loops") */ #include <bits/stdc++.h> using namespace std; #define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr) #define FOR(i, a, b) for(int i = (a); i <= (b); i++) #define REP(n) FOR(O, 1, (n)) #define pb push_back #define f first #define s second typedef long double ld; typedef long long ll; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<pii> vii; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int MAXN = 500100, MAXK = 20; const ll INF = 1e16; //const ll MOD = 1e9+7; //const ll MOD = 998244353; void setIO() { FAST_IO; } void setIO(string s) { FAST_IO; freopen((s+".in").c_str(), "r", stdin); freopen((s+".out").c_str(), "w", stdout); } int n, k; ll t[MAXN]; vi srt; int main() { setIO(); cin >> n >> k; ll ans = 0; FOR(i, 1, n) { cin >> t[i]; } ans += t[n] - t[1] + 1; FOR(i, 1, n-1) srt.pb(-t[i+1] + t[i]+1); sort(srt.begin(), srt.end()); FOR(i, 0, k-2) ans += min(0, srt[i]); cout << ans << "\n"; return 0; }

Compilation message (stderr)

stove.cpp: In function 'void setIO(std::string)':
stove.cpp:37:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |     freopen((s+".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
stove.cpp:38:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |     freopen((s+".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...