1017. Queueing at Bank

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <functional>
#include <string>
#include <queue>

using namespace std;

int N,K;

class Person
{
public:
	int time;
	int ptime;
};
Person persons[10005];
int window[105];

int comp(const Person& a, const Person& b)
{
	return a.time < b.time;
}
int main()
{
	scanf("%d %d",&N,&K);
	for(int i=0;i<N;i++)
	{
		
		int h,m,s;
		int ptime;
		scanf("%d:%d:%d %d",&h,&m,&s,&ptime);
		int time = h*60*60 + m*60 +s;
		persons[i].ptime = ptime*60;
		persons[i].time = time;
	}
	sort(persons,persons+N,comp);

	for(int i=0;i<K;i++)
		window[i] = 8*60*60;
	
	
	int sumWait = 0;
	int num=0;
	for(int i=0;i<N;i++)
	{
		if(persons[i].time > 17*60*60)
			break;
		int* pWin = min_element(window,window+K);
		int ptime = max(*pWin,persons[i].time);
		sumWait += ptime - persons[i].time;
		*pWin = ptime+persons[i].ptime;
		num++;
	}
	
	printf("%.1f",((float)sumWait/num)/60);
	return 0;
}



你可能感兴趣的:(1017. Queueing at Bank)