hellow,
i was solving a div 4 c so i am wondering why my code fialed can anyone give me a where it will help pls 306053812
thanks ! in advice
# | User | Rating |
---|---|---|
1 | tourist | 3856 |
2 | jiangly | 3747 |
3 | orzdevinwang | 3706 |
4 | jqdai0815 | 3682 |
5 | ksun48 | 3591 |
6 | gamegame | 3477 |
7 | Benq | 3468 |
8 | Radewoosh | 3462 |
9 | ecnerwala | 3451 |
10 | heuristica | 3431 |
# | User | Contrib. |
---|---|---|
1 | cry | 167 |
2 | -is-this-fft- | 162 |
3 | Dominater069 | 160 |
4 | Um_nik | 158 |
5 | atcoder_official | 157 |
6 | Qingyu | 156 |
7 | adamant | 151 |
7 | djm03178 | 151 |
7 | luogu_official | 151 |
10 | awoo | 146 |
hellow,
i was solving a div 4 c so i am wondering why my code fialed can anyone give me a where it will help pls 306053812
thanks ! in advice
Name |
---|
Well the thing your doing is not optimal. You are checking if first element is bigger than second if yes then you are using the operation but the optimal thing to do is to just apply the operation whenever it gives a lesser number than the current number and also maintains that the previous value is smaller
k-a[i] can be larger than or equal to a[i-1] (k >= a[i] + a[i-1])
Instead, you should check for k-a[i] instead of k-a[i-1], if k-a[i] and doesn't work then just straight up cout << "NO"
Doing the operation at most once does nothing in this problem
When you do 2 operations: k-(k-a[i]) = k-k+a[i] = a[i]
This means that there are only 2 possibilities: a[i] and k-a[i]