Submission #1033682

#TimeUsernameProblemLanguageResultExecution timeMemory
1033682vjudge1Stove (JOI18_stove)C++17
100 / 100
19 ms1396 KiB
#pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> using namespace std; // #define int long long // #define double long double #define endl '\n' #define fastIO ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); #define setmin(x, y) x = min((x), (y)) #define setmax(x, y) x = max((x), (y)) #define sqr(x) ((x) * (x)) #define fi first #define se second #define all(x) x.begin(), x.end() // mt19937 hdp(chrono::high_resolution_clock::now().time_since_epoch().count()); // int rand(int l, int r){return l + ((hdp() % (r - l + 1)) + r - l + 1) % (r - l + 1);} const int NM = 1e5 + 5; const int inf = 1e9; int n, a[NM], k, t[NM], ans; vector<int> v; signed main() { fastIO if (fopen("in.txt", "r")) { freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); } cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> t[i]; if (i > 1) v.push_back(max(0, t[i] - t[i - 1] - 1)); } ans = t[n] - t[1] + 1; k--; sort(v.begin(), v.end(), greater<int>()); for (int i = 0; i < k; i++) ans -= v[i]; cout << ans; }

Compilation message (stderr)

stove.cpp: In function 'int main()':
stove.cpp:31:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |         freopen("in.txt", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
stove.cpp:32:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |         freopen("out.txt", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...