Maximum waterflow impl in java