天天写算法之Assignments

我正在做凸包问题,结果忽然出现了一个贪心-。-|||

一开始没都明白题目,以为会有多余的学生,想到了背包,emmm,后来发现0.0
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cstring>
#define MAX 1007

using namespace std;

int n,t;
int a[MAX],b[MAX];

int cmp ( int a , int b )
{
    return a > b;
}

int main ( )
{
    while ( ~scanf ( "%d%d" , &n , &t ) )
    {
        for ( int i = 0 ; i < n ; i++ )
            scanf ( "%d" , &a[i] );
        for ( int i = 0 ; i < n ; i++ )
            scanf ( "%d" , &b[i] );
        sort ( a , a+n );
        sort ( b , b+n , cmp );
        int sum = 0;
        for ( int i = 0 ; i < n ; i++ )
            if ( a[i] + b[i] > t )
                sum += a[i] + b[i] - t;
        printf ( "%d\n" , sum );
    }
}
惊不惊喜?意不意外?
阅读更多

没有更多推荐了,返回首页