SRM469 Div2 Medium(600) TheMoviesLevelTwoDivTwo

TheMoviesLevelTwoDivTwo

並べ方を全て試す。

#include <vector>
#include <algorithm>

using namespace std;

class TheMoviesLevelTwoDivTwo
{
public:
    vector <int> find( vector <int> length, vector <int> scary );
};

vector <int> TheMoviesLevelTwoDivTwo::find( vector <int> length, vector <int> scary )
{
    int n = (int)length.size();

    vector<int> movie;
    for ( int i=0; i<n; i++ )
        movie.push_back( i );

    int maxn = -1;
    vector<int> maxorder;

    do
    {
        int scar = 74;
        int num;
        for ( num=0; num<n; num++ )
        {
            scar -= scary[movie[num]];

            if ( scar < 0 )
                break;

            scar += 47;
            scar -= length[movie[num]] - scary[movie[num]];

            if ( scar < 0 )
                break;
        }

        if ( num > maxn )
        {
            maxn = num;
            maxorder = movie;
        }
    }
    while ( next_permutation( movie.begin(), movie.end() ) );

    return maxorder;
}