SRM479 Div2 Medium(500) TheCoffeeTimeDivTwo

TheCoffeeTimeDivTwo

茶とコーヒーを同時にフラスコに入れることはできない。それぞれ遠い方から順に7人ずつ配っていけば良い。

#include <vector>
#include <algorithm>

using namespace std;

class TheCoffeeTimeDivTwo
{
public:
    int find( int n, vector <int> tea );
};

int TheCoffeeTimeDivTwo::find( int n, vector <int> tea )
{
    int m = (int)tea.size();
    vector<int> coffee;

    for ( int i=1; i<=n; i++ )
        if ( ::find( tea.begin(), tea.end(), i ) == tea.end() )
            coffee.push_back( i );

    int s = 0;

    sort( tea.begin(), tea.end() );
    for ( int i=m-1; i>=0; i-=7 )
        s += 2*tea[i] + 47;
    for ( int i=n-m-1; i>=0; i-=7 )
        s += 2*coffee[i] + 47;

    s += 4*n;

    return s;
}