Last active
January 5, 2016 09:51
-
-
Save MagallanesFito/e89d425bd4dafa7cbb6c to your computer and use it in GitHub Desktop.
solucion Agente A, Heroe Nacional. Problema preselectivo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <bits/stdc++.h> | |
| using namespace std; | |
| typedef unsigned long long ULL; | |
| ULL n,t,a,b,d,suma; | |
| int main(){ | |
| cin>>n; | |
| cin>>t; | |
| suma = 0; | |
| while(n--){ | |
| cin>>a>>b; | |
| d = __gcd(a,b); | |
| if(d == 1){ | |
| suma+=min(a,b)+1; | |
| continue; | |
| } | |
| while(a!=0 && b!=0){ | |
| a-=d; | |
| b-=d; | |
| suma++; | |
| if(b == 0 && a!=0){ | |
| a=0; | |
| suma++; | |
| } | |
| if(a == 0 && b!=0){ | |
| b = 0; | |
| suma++; | |
| } | |
| } | |
| } | |
| if(suma-1 > t) cout << "El Agente A no sera heroe nacional, el Doctor B destruira su pais"; | |
| else cout << suma-1; | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment