Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
WHY FEW ACCEPTED FOR SUCH A EASY PROBLEM#include <cstdio> #include <algorithm> #include <iostream> #define maxn (10000 + 10) using namespace std; const int inf = 1000000000; int n, d[maxn], ans, m, e; pair<pair<int, int>, int>p[maxn]; void init(){ for(int i = 0; i < n; i++) d[i] = inf; ans = inf; } int main(){ scanf("%d %d %d", &n, &m, &e); init(); for(int i = 0; i < n; i++){ scanf("%d %d %d", &p[i].first.first, &p[i].first.second, &p[i].second); } sort(p, p + n); for(int i = 0; i < n; i++) if(p[i].first.first == m) d[i] = 0; for(int i = 0; i < n; i++){ int c = p[i].second, t = d[i], pl = p[i].first.second + 1; for(int j = i + 1; j < n && p[j].first.first <= pl; j++){ d[j] = min(d[j], t + c); } } for(int i = 0; i < n; i++){ if(p[i].first.second == e){ ans = min(ans, d[i] + p[i].second); } } printf("%d\n", (ans != inf ? ans : -1)); return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator