BuringStraw

BuringStraw

USACO 1.1.2| Greedy Gift Givers

Starting USACO again?
It's quite easy, but tricky. Note that the remaining money after giving gifts should not be counted.

#include<bits/stdc++.h>
using namespace std;

const int MAXN=15;

struct mem{
	string name;
	int money;
} a[MAXN];

int n;

int fnd(string nm){
	for(int i=1;i<=n;++i){
		if(a[i].name==nm){
			return i;
		}
	}
	return 0;
}

int main(){
	cin>>n;
	for(int i=1;i<=n;++i){
		cin>>a[i].name;
	}
	string name;//Name 
	for(int l=1;l<=n;++l){
		int yq,rs;//Initial money, number of recipients 
		cin>>name>>yq>>rs;
		int fd=fnd(name);
		if(rs==0){
			a[fd].money+=yq;
			continue;
		}
		a[fd].money-=(yq-yq%rs);
		yq/=rs;
		for(int i=1;i<=rs;++i){
			string sr;//Recipient 
			cin>>sr;
			int fd2=fnd(sr);
			a[fd2].money+=yq;
		}
	}
	
	for(int i=1;i<=n;++i){
		cout<<a[i].name<<' '<<a[i].money<<'\n';
	}
	
	return 0;
}
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.