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 |
wrong answerwhat the wrong with this code ? : #include <iostream> #include <vector> #include <algorithm> using namespace std; int n,t; vector <pair<int,int> > cow; int main(){ cin >>n >>t; for (int i=0;i<n;i++){ int a,b; cin >>a >>b; cow.push_back(make_pair(a,b)); } sort (cow.begin(),cow.end()); int e=1,mx=-1,c=0,p=0; while (e<=t && p<cow.size()){ while (cow[p].first<=e){ mx=max(mx,cow[p].second); p++; } if (mx<e){ cout <<-1<<endl; return 0; } c++; e=mx+1; } if (e==t+1) cout <<c<<endl; else cout <<-1<<endl; return 0; } it's better to give me e good test case and don't say my bug! tnx ! :) Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator