This solution works as long as nothing bad can happen if group 2 is executed before group 1.
If something bad can happen (e.g., loss of funds, ways for an attacker to steal funds, moving the contract in a dangerous state, …), then you should absolutely not use the above. Indeed, an attacker (who controls the block proposer, or the correct relays, or the node you used, or …) can easily drop group 1 and then fund the account A themselves.
If you need group 1 to happen before group 2, the best solution I know of is to use a smart contract for that purpose. There are many ways to implement it, but a very naive way is to have a counter you increment.