HDU : Doing Homework again


// @BEGIN_OF_SOURCE_CODE

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <sstream>
#include <set>
#include <math.h>
#define pi acos(-1.0)
#define N 1000000
using namespace std;

struct work {
    long long day;
    long long weight;
} a [1000 + 10];

bool cmp (work x, work y)
{
    if ( x.weight > y.weight )
        return true;
    return false;
}

int main ()
{
    int testCase;
    scanf ("%d", &testCase);

    while ( testCase-- ) {
        int n;
        scanf ("%d", &n);

        map <long long, bool> sequence;

        for ( long long i = 0; i < n; i++ )
            scanf ("%lld", &a [i].day);

        for ( long long i = 0; i < n; i++ )
            scanf ("%lld", &a [i].weight);

        sort (a, a + n, cmp);
        long long cost = 0;

        for ( long long i = 0; i < n; i++ ) {
            if ( sequence [a [i].day] == false )
                sequence [a [i].day] = true;
            else {
                bool found = false;
                for ( long long j = a [i].day - 1; j >= 1; j-- ) {
                    if ( sequence [j] == false ) {
                        found = true;
                        sequence [j] = true;
                        break;
                    }
                }

                if ( !found )
                    cost += a [i].weight;
            }
        }

        printf ("%lld\n", cost);
    }

    return 0;
}

// @END_OF_SOURCE_CODE
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