-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFarm.java
More file actions
49 lines (45 loc) · 1.52 KB
/
Farm.java
File metadata and controls
49 lines (45 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import java.util.*;
import java.io.*;
public class Main {
static int a, b, n, w, sheep, goat, cnt;
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
static StringTokenizer st;
public static void main(String[] args) throws Exception{
input();
}
public static void strToken() throws Exception{
st = new StringTokenizer(br.readLine());
}
public static void input() throws Exception{
strToken();
a = Integer.parseInt(st.nextToken());
b = Integer.parseInt(st.nextToken());
n = Integer.parseInt(st.nextToken());
w = Integer.parseInt(st.nextToken());
for (int i = 1; i < n / 2 + 1; i++) {
if(a * i + b * (n - i) == w) {
if(sheep != 0){
sheep = 0;
break;
}else{
sheep = i;
goat = n - i;
}
}
if((b * i + a * (n - i) == w) && i != (n - i)){
if(sheep != 0){
sheep = 0;
break;
}else{
sheep = n - i;
goat = i;
}
}
}
if(sheep == 0) bw.append("-1");
else bw.append(String.valueOf(sheep)).append(" ").append(String.valueOf(goat));
bw.flush();
bw.close();
}
}