제출 #1252699

#제출 시각아이디문제언어결과실행 시간메모리
1252699VKhangStove (JOI18_stove)C++20
100 / 100
15 ms1988 KiB
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5, MOD = 1e9 + 7; const long long L = 1e18; #define ll long long #define fi first #define se second #define yes {cout << "YES";return;} #define no {cout << "NO"; return;} #define pb push_back #define MASK(i) (1ll << (i)) #define BIT(i, s) ((1ll << (i)) & (s)) #define all(a) a.begin(), a.end() int n, k; int a[N]; void solve() { cin >> n >> k; for (int i = 1; i <= n; i++){ cin >> a[i]; } vector <pair <int, int>> s; for (int i = 1; i < n; i++){ s.pb({a[i + 1] - a[i] - 1, i}); } sort(all(s)); int ans = n; for (int i = 0; i < s.size() && n > k; i++){ ans += s[i].fi; n--; } cout << ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); if (fopen("VKhang.inp","r")){ freopen("VKhang.inp","r",stdin); freopen("VKhang.out","w",stdout); } solve(); return 0; }

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

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