codeforces 230A

来源:互联网 发布:拉普拉斯变换公式矩阵 编辑:程序博客网 时间:2024/05/01 20:20

简单的贪心算法。。。

按Dragon的strength排序。。。



#include <algorithm>                                                                                                                            #include <iostream> using namespace std; struct cmp {    int x, y;}array[1005]; bool tmp ( cmp a, cmp b ) {    return a.x < b.x;} int main ( ) {    int s, n, x, y, ans;    ans = 0;    cin >> s >> n;    for ( int i = 0; i < n; ++i )        cin >> array[i].x >> array[i].y;    sort ( array, array + n, tmp );     for ( int i = 0; i < n; ++i ) {        if ( s > array[i].x ) {            s += array[i].y;            ans++;        }    }     if ( ans == n ) cout << "YES" << endl;    else cout << "NO" << endl;}




原创粉丝点击