fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4.  
  5. ll n,x,y,b[3000000],c=0,t;
  6. bool m=false;
  7. vector<pair<ll,ll>>a;
  8. int main() {
  9. cin>>n>>t;
  10. for(int i=1;i<=n;i++){
  11. cin>>x>>y;
  12. if(x>y){
  13. a.push_back(make_pair(y,x));
  14. m=true;
  15. }
  16. c=max(c,x);
  17. }
  18. sort(a.begin(),a.end());
  19. if(m) t+=(c-a[0].first)*2;
  20. cout<<t;
  21. return 0;
  22. }
Success #stdin #stdout 0s 5316KB
stdin
2 533969263
279488210 145660682
473285129 386724188
stdout
1189218157