A general form of the weak maximum principle and some applications