Skip to content

Instantly share code, notes, and snippets.

@IKKO-Ohta
Created April 30, 2017 14:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IKKO-Ohta/452ef5320798d41daa1274bd00658b9e to your computer and use it in GitHub Desktop.
Save IKKO-Ohta/452ef5320798d41daa1274bd00658b9e to your computer and use it in GitHub Desktop.
AOJ1052,Old Bridges
#define REP(i,n) for (int i=0;i<(n);i++)
#include <iostream>
#include <algorithm>
using namespace std;
const int MAX_N = 25;
typedef pair<int,int> P;
int n;
int v,l;
P p[MAX_N];
void solve(){
int accum = 0;
sort(p,p+n);
REP(i,n){
accum += p[i].second;
if (accum <= p[i].first){
continue;
}else{
cout << "No" << endl;
return;
}
}
cout << "Yes" << endl;
return;
}
int main(){
while(1){
cin >> n;
if (n == 0) break;
REP(i,n){
cin >> v >> l;
p[i] = P(l,v);
}
solve();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment