-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMore_Cake.cpp
60 lines (53 loc) · 1021 Bytes
/
More_Cake.cpp
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
50
51
52
53
54
55
56
57
58
59
60
/*
https://www.codechef.com/PCO12020/problems/MORECAKE
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
#define pi pair<int , int>
#define pll pair<ll , ll>
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vector<int>>
#define vvll vector<vector<ll>>
#define fast ios::sync_with_stdio(0) ; cin.tie(0) ;
#define fastcout ios::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0);
const ll mod = 1000000007;
ll extra , left;
void solv(){
ll val ,n , s , k;
cin >> val >> n >> s >> k;
ll temp = s;
for(int i = 0 ; i < n ; ++i){
val -= temp;
temp *= k;
}
extra += val;
if( val > 0){
cout << "POSSIBLE " << val << endl;
}
else if(val == 0){
cout << "POSSIBLE" << endl;
}
else {
cout << "IMPOSSIBLE " << -1*val << endl;
}
}
int main() {
fast;
int tt;
cin >> tt;
// // tt =1;
extra = 0 ;
while (tt--) {
solv();
}
if(extra >= 0){
cout << "POSSIBLE"<<endl;
}
else{
cout << "IMPOSSIBLE"<< endl;
}
return 0;
}