Sunday, November 20, 2011

[UVa] 11679 - Sub Prime

At a first glance, in particular after reading the name, at least I thought it's about Primes :P. It's pure ad hoc, simulation.

#include <set>
#include <map>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>

using namespace std;

class bank
{
    public:
    int tot_money;
    vector< pair<int,int> > dList;
    void init() {tot_money=0; dList.clear();}
};

bank banks[30];

int main()
{

    //freopen("in.txt","r+",stdin);
    //freopen("out.txt","w+",stdout);


    int b, n, d, c, m, i, j, increase, decrease;
    bool valid;

    while (scanf("%d %d",&b,&n)==2)
    {
        if (!b && !n)
            break;
// Input Start
        for (i=1 ; i<=b ; i++)
        {
            banks[i].init();
            scanf("%d",&banks[i].tot_money);

        }

        for (i=1 ; i<=n ; i++)
        {
            scanf("%d %d %d",&d,&c,&m);

            banks[d].dList.push_back( make_pair(c,m) );
        }
// Input End


// Process Start
        for (i=1 ; i<=b ; i++)
        {
            for (j=0 ; j<banks[i].dList.size() ; j++)
            {
                increase = banks[i].dList[j].first;
                decrease = banks[i].dList[j].second;

                banks[increase].tot_money+=decrease;
                banks[i].tot_money-=decrease;
            }
        }


        for (i=1, valid=true ; i<=b ; i++)
        {
            if (banks[i].tot_money<0)
            {
                valid = false;
                break;
            }
        }

        if (valid) printf("S\n");
        else printf("N\n");

// Process End

    }
    return 0;
}

No comments:

Post a Comment

Post your comment here. If you want to say something about programming problems, scripts, software etc, please try to be as descriptive as possible.

Connect Rapoo MT750S with Linux (Tested on Manjaro)

 I bought this obvious copy of MX Master 2S in hopes of having the device switching functionality along with a lightweight body because I ha...