제출 #754575

#제출 시각아이디문제언어결과실행 시간메모리
754575Nika533Stove (JOI18_stove)C++14
100 / 100
23 ms5484 KiB
#pragma GCC diagnostic warning "-std=c++11"
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define f first
#define s second
#define MOD 1000000007
#define flush fflush(stdout)
#define all(x) (x).begin(),(x).end()
using namespace std;
int n,m,T,k;
string s;
void test_case() {
	cin>>n>>k;
	int arr[n];
	for (int i=0; i<n; i++) {
		cin>>arr[i];
	}
	vector<pair<int,int>> v;
	int l=0;
	int r=0;
	for (int i=1; i<n; i++) {
		if (arr[i]==arr[i-1]) {
			r++;
		}
		else {
			v.pb({arr[l],arr[r]});
			l=i;
			r=i;
		}
	}
	v.pb({arr[l],arr[r]});
	m=v.size();
	vector<int> p;
	for (int i=0; i<m; i++) {
		//cout<<v[i].f<<" "<<v[i].s<<endl;
	}
	for (int i=1; i<m; i++) {
		p.pb(v[i].f-v[i-1].s-1);
	}
	sort(all(p));
	int ans=n;
	for (int i=0; i<min(m-1,n-k); i++) {
		ans+=p[i];
	}
	cout<<ans<<endl;
}
main () {
	ios :: sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	T=1;
	//cin>>T;
	while (T--) {
		test_case();
	}
}

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

stove.cpp:1:32: warning: '-std=c++11' is not an option that controls warnings [-Wpragmas]
    1 | #pragma GCC diagnostic warning "-std=c++11"
      |                                ^~~~~~~~~~~~
stove.cpp:48:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   48 | main () {
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...