제출 #1068198

#제출 시각아이디문제언어결과실행 시간메모리
1068198quangminh412Stove (JOI18_stove)C++14
100 / 100
20 ms2268 KiB
#include <bits/stdc++.h>
using namespace std;

/*
  John Watson
  https://codeforces.com/profile/quangminh98

  Mua Code nhu mua Florentino !!
*/

#define faster() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long

const int maxn = 1e5 + 9;

int t[maxn];
int n, k;

signed main()
{
	if (fopen("test.inp", "r"))
	{
		freopen("test.inp", "r", stdin);
		freopen("test.out", "w", stdout);
	}
	faster();

	cin >> n >> k;
	vector<int> tmp;
	for (int i = 1; i <= n; i++)
	{
		cin >> t[i];
		if (i > 1)
			tmp.push_back(t[i] - t[i - 1]);
	}
	sort(tmp.begin(), tmp.end(), greater<int>());
	ll sum = 0;
	for (int i = 0; i < k - 1; i++)
		sum += tmp[i] - 1;
		
	cout << t[n] - t[1] + 1 - sum << '\n';

	return 0;
}

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

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