U E D R , A S I H C RSS

[Lovely]boy^_^/[Lovely]boy^_^/USACO/Barn


#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;

vector<int> getDistance(const vector<int>& ar)
{
	vector<int> ret( ar.size() - 1 );
	for(int i = 0 ; i < ar.size() - 1 ; ++i)
		ret[i] = ar[i+1] - ar[i];
	return ret;
}

vector<int> getPivot(int numPivot, const vector<int>& distance)
{
	vector<int> ret(distance);
	sort(ret.begin(), ret.end(), greater<int>());
	ret.erase(ret.begin() + numPivot - 1, ret.end());
	return ret;
}

vector<int> getDatas(int& numPivot)
{
	int max, iter;
	ifstream fin("barn1.in");
	fin >> numPivot >> max >> iter;
	vector<int> ar(iter);
	if(numPivot > iter)
		numPivot = iter;
	for(int i = 0 ; i < iter ; ++i)
		fin >> ar[i];
	fin.close();
	sort(ar.begin(), ar.end());
	return ar;
}

int getTotal(int numPivot, const vector<int>& ar, const vector<int>& pivots)
{
	int ret = ar[ ar.size() - 1 ] - ar[0];
	for(int i = 0 ; i < pivots.size() ; ++i)
		ret -= pivots[i];
	ret += numPivot;
	return ret;
}

int main()
{
	int numPivot;
	vector<int> data = getDatas(numPivot);
	vector<int> distance = getDistance(data);
	vector<int> pivots = getPivot(numPivot, distance);
	ofstream fout("barn1.out");
	fout << getTotal(numPivot, data, pivots) << endl;
	fout.close();
	return 0;
}


["Lovelyboy^_^/USACO"]
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2013-11-15 01:12:58
Processing time 0.0139 sec