fork download
  1. //USACO 2017 December Contest, Gold
  2. //Problem 3. Haybale Feast
  3. #include<bits/stdc++.h>
  4. #define int long long
  5. using namespace std;
  6. void usaco(){
  7. freopen("hayfeast.in","r",stdin);
  8. freopen("hayfeast.out","w",stdout);
  9. }
  10.  
  11. signed main() {
  12. ios::sync_with_stdio(false); cin.tie(nullptr);
  13. usaco();
  14. int n,m; cin>>n>>m;
  15. pair<int,int> a[n]; for(auto &[x,y]:a) cin>>x>>y;
  16. int s=0,ans=2e18,j=0;
  17. multiset<int>st;
  18. for(int i=0;i<n;i++){
  19. auto [x,y]=a[i];
  20. s+=x; st.insert(y);
  21. while(j<i && s-a[j].first >=m) {
  22. st.erase(st.find(a[j].second));
  23. s-=a[j].first;
  24. j++;
  25. }
  26. if(s>=m) ans=min(ans,*st.rbegin());
  27. }
  28. cout<<ans;
  29. }
  30.  
Success #stdin #stdout 0.02s 8340KB
stdin
Standard input is empty
stdout
Standard output is empty