제출 #482835

#제출 시각아이디문제언어결과실행 시간메모리
482835glomeStove (JOI18_stove)C++17
100 / 100
68 ms7148 KiB
#include <bits/stdc++.h>

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n,k;
	cin >> n >> k;
	vector<pair<int, int>> d;
	vector<int> y(n);
	for (int i = 0; i<n; i++) {
		cin >> y[i];
	}
	for (int i = 0; i<n-1; i++) {
		if(y[i] + 1 == y[i + 1]) {
			continue;
		}
		d.push_back({y[i] + 1, y[i+1] - 1});
	}
	sort(d.begin(), d.end(), [&] (pair<int, int> A, pair<int, int> B) {
		return A.second - A.first > B.second - B.first;
	});
	map<int, bool> mark;
	for (int i = k - 1; i<d.size(); i++) {
		mark[d[i].first - 1] = 1;
	}
	int ans = 0;
	for (int i = 0; i<n - 1; i++) {
		if(mark[y[i]]) {
			if(i == 0) {
				ans += (y[i + 1] + 1) - y[i];
				continue;
			}
			if(mark[y[i-1]]) {
				ans += y[i + 1] - y[i];
			}
			else {
				ans +=( y[i + 1] + 1) - y[i];
			}
		}
		else {
			if(i == 0) {
				ans++;
				continue;
			}
			if(!mark[y[i-1]]) {
				ans++;
			}
		}
	}
	if(n == 1) {
		ans++;
	}
	if(n >= 2) {
		if(!mark[y[n-2]]) {
			ans++;
		}
	}
	cout << ans << '\n';
	return 0;
}

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

stove.cpp: In function 'int main()':
stove.cpp:25:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |  for (int i = k - 1; i<d.size(); i++) {
      |                      ~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...