제출 #1146075

#제출 시각아이디문제언어결과실행 시간메모리
1146075CrabCNHStove (JOI18_stove)C++20
100 / 100
11 ms1480 KiB
#include <bits/stdc++.h> #define task "BriantheCrab" #define ll long long #define pii pair <int, int> #define fi first #define se second #define szf sizeof #define sz(s) (int)((s).size()) using namespace std; template <class T> void mini (T &t, T f) {if (t > f) t = f;} template <class T> void maxi (T &t, T f) {if (t < f) t = f;} const int maxN = 1e5 + 5; const int inf = 1e9 + 7; const int mod = 1e9 + 7; int n, k; int a[maxN]; void Solve () { cin >> n >> k; for (int i = 1; i <= n; i ++) { cin >> a[i]; } vector <int> dif; for (int i = 2; i <= n; i ++) { dif.push_back ({a[i] - a[i - 1]}); } sort (dif.begin (), dif.end ()); int res = n; int cur = n - k; for (auto it : dif) { if (cur == 0) { break; } res += it - 1; //cout << it << '\n'; cur --; } cout << res; return; } signed main () { cin.tie (nullptr) -> sync_with_stdio (false); if (fopen (task".inp", "r")) { freopen (task".inp", "r", stdin); freopen (task".out", "w", stdout); } int t = 1; //cin >> t; while (t --) { Solve (); } return 0; } // Belligerent :)

컴파일 시 표준 에러 (stderr) 메시지

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