Submission #1519542


Source Code Expand

#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <tuple>
#include <bitset>

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <fstream>
#include <random>
//#include <time.h>
#include <ctime>
#pragma endregion //#include
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)
#define ALL(X) X.begin(), X.end()
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef std::pair<LL,LL> PLL;//
typedef std::pair<int,int> PII;//
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)1e18+20;
const double PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

//見える高さを計算
LL f(vector<LL>& v){
	LL max = v[0];
	LL ans = 1;
	int size = v.size();
	for(int i=1;i<size;++i){
		if( max < v[i] ){
			++ans;
			max = v[i];
		}
	}
	return ans;
}

//posを見えるようにするためのコスト
pair<LL,LL> cost(vector<LL>& v,int pos){
	LL ans = 0;
	LL add = 0;
	LL MAX = 0;
	int size = v.size();
	vector<bool> hi(size,false);
	hi[0] = true;
	MAX = v[0];
	for(int i=1;i<size;++i){
		if( MAX < v[i] ){
			hi[i] = true;
			MAX = v[i];
		}
	}

	//posより前の最大値
	MAX = 0;
	for(int i=0;i<pos;++i){
		MAX = max(MAX,v[i]);
	}
	if( MAX >= v[pos] ){
		add = MAX -v[pos] + 1;
		ans = MAX -v[pos] + 1;
	}
	
	MAX = v[pos];
	for(int i=pos+1;i<size;++i){
		if( hi[i] ){
			if( MAX < v[i] ){
				break;
			}else{
				ans += MAX-v[i]+1;
			}
		}
	}
	pair<LL,LL> res(ans,add);
	return res;
}
void solve(){
	int N,K;
	cin >> N >> K;
	vector<LL> A(N);
	vector<LL> diff(N,0);
	for(int i=0;i<N;++i){
		cin >> A[i];
		if( i ){
			diff[i] = A[i]-A[i-1];
		}
	}

	LL ans = 0;
	pair<LL,LL> MIN,temp;
	while( f(A) < K ){
		MIN.first = LINF;
		int pos = -1;
		for(int i=N-1;i>0;--i){
			temp = cost(A,i);
			if( temp.first > 0 && temp.first < MIN.first){
				MIN = temp;
				pos = i;
			}
		}
		A[pos] += MIN.second;
		ans += MIN.second;
	}
	cout << ans << endl;
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()

Submission Info

Submission Time
Task B - Buildings are Colorful!
User akarin55
Language C++14 (GCC 5.4.1)
Score 210
Code Size 2683 Byte
Status WA
Exec Time 1 ms
Memory 256 KB

Judge Result

Set Name Sample Subtask1 Subtask2 Subtask3
Score / Max Score 0 / 0 120 / 120 90 / 90 0 / 140
Status
AC × 2
AC × 2
AC × 3
AC × 8
WA × 1
Set Name Test Cases
Sample sub0_in1.txt, sub0_in2.txt
Subtask1 sub1_in1.txt, sub1_in2.txt
Subtask2 sub2_in1.txt, sub2_in2.txt, sub2_in3.txt
Subtask3 sub0_in1.txt, sub0_in2.txt, sub1_in1.txt, sub1_in2.txt, sub2_in1.txt, sub2_in2.txt, sub2_in3.txt, sub3_in1.txt, sub3_in2.txt
Case Name Status Exec Time Memory
sub0_in1.txt AC 1 ms 256 KB
sub0_in2.txt AC 1 ms 256 KB
sub1_in1.txt AC 1 ms 256 KB
sub1_in2.txt AC 1 ms 256 KB
sub2_in1.txt AC 1 ms 256 KB
sub2_in2.txt AC 1 ms 256 KB
sub2_in3.txt AC 1 ms 256 KB
sub3_in1.txt AC 1 ms 256 KB
sub3_in2.txt WA 1 ms 256 KB