Submission #408957

#TimeUsernameProblemLanguageResultExecution timeMemory
408957MohamedAhmed04Strange Device (APIO19_strange_device)C++14
100 / 100
551 ms25312 KiB
#include <bits/stdc++.h> using namespace std ; const long long inf = 4e18 ; const int MAX = 1e5 + 10 ; bool Overflow_Mul(long double x , long double y) { return (x * y > inf) ; } int arr[MAX] ; int n ; long long a , b ; vector< pair<long long , long long> >vp ; int main() { ios_base::sync_with_stdio(0) ; cin.tie(0) ; cin>>n>>a>>b ; long long x = a / __gcd(a , b+1ll) ; if(Overflow_Mul(x , b)) x = inf ; else x *= b ; long long st = -1 ; for(int i = 0 ; i < n ; ++i) { long long l , r ; cin>>l>>r ; if(r-l+1ll >= x) return cout<<x<<"\n" , 0 ; if((r % x) < (l % x)) st = max(st , (r % x)) , vp.emplace_back((l % x) , x-1ll) ; else vp.emplace_back((l % x) , (r % x)) ; } sort(vp.begin() , vp.end()) ; long long ans = st+1ll , Max = st ; for(auto &p : vp) { Max = max(Max , p.first - 1ll) ; ans += max(0ll , p.second - Max) ; Max = max(Max , p.second) ; } return cout<<ans<<"\n" , 0 ; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...