Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- int main(){
- int a, b, c, d, n;
- cin>>a>>b>>c>>d>>n;
- long long answer;
- if (a>c){
- if (b>d){
- if (n/(a-c)>n/(b-d)){
- answer=((n-b-1)/(b-d)+2)*(a+b+c+d)-c-d;
- }else{
- answer=((n-a-1)/(a-c)+2)*(a+b+c+d)-b-c-d;
- }
- }else{
- if (n/(a-c)>n/(d-b)){
- answer=((n-1)/(d-b)+1)*(a+b+c+d);
- }else{
- answer=((n-a-1)/(a-c)+2)*(a+b+c+d)-b-c-d;
- }
- }
- }else{
- if (b>d){
- if (n/(c-a)>n/(b-d)){
- answer=((n-b-1)/(b-d)+2)*(a+b+c+d)-c-d;
- }else{
- answer=((n-1)/(c-a)+1)*(a+b+c+d)-d;
- }
- }else{
- if (n/(a-c)>n/(d-b)){
- answer=((n-1)/(d-b)+1)*(a+b+c+d);
- }else{
- answer=((n-1)/(c-a)+1)*(a+b+c+d)-d;
- }
- }
- }
- cout<<answer<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement