USACO 1.3.1 – Mixing Milk


#include <iostream>
#include <fstream>
#include <string>

using namespace std;

 int main_milk() {
	ofstream fout("milk.out");
	ifstream fin("milk.in");
	int i, wanted, F, cost = 0, stk[1005] = { 0 }, price, milk;

	fin >> wanted >> F >> price >> milk;
	for (i = 0; i < F; i += 1, fin >> price >> milk)
		stk[price % 1003] += milk;

	for (i = 0; i < 1003 && wanted; ++i)
		if (stk[i]) {
			if (stk[i] >= wanted)
				cost += i * wanted, wanted = 0;
			else
				cost += i * stk[i], wanted -= stk[i];
		}
	fout << cost << endl;

	return 0;
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: