/* ID: garakch1 LANG: C++ PROB: milk2 */ #include <cstdio> #include <vector> #include <algorithm> bool cmp(const std::pair<int, int> &left, const std::pair<int, int> &right) { return left.first < right.first; } int main() { freopen("milk2.in", "r", stdin); freopen("milk2.out", "w", stdout); std::vector< std::pair<int, int> > v; int n, a, b; scanf("%d", &n); for (int i=0; i<n; i++) { scanf("%d%d", &a, &b); v.push_back(std::make_pair(a, b)); } sort(v.begin(), v.end(), cmp); //for (int i=0; i<n; i++) printf("%d %d\n", v[i].first, v[i].second); int left=v[0].first, right=v[0].second, idle=0, cont; cont=right-left; for(int i=0; i<n; i++) { if(v[i].first>right) idle=std::max(v[i].first-right, idle), left=v[i].first, right=v[i].second; else if(v[i].second>right) right=v[i].second, cont=std::max(right-left, cont); } printf("%d %d\n", cont, idle); return 0; }
Wednesday, January 31, 2018
usaco Milking Cows solution
usaco Milking Cows solution
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment