We perform grand canonical Monte Carlo simulations to study the pH titrations of isolated polyampholytes and polyelectrolyte-polyampholyte complexes in dilute solutions. Our simulations indicate that the electrostatic interactions promote the coexistence of opposite charges along the polyampholyte chain during titration. The repulsion between excess charges typically dominates the electrostatic interaction and leads to polymer stretching. Salt ions can screen the repulsion between excess charges as well as the fluctuation-induced attraction between opposite charges, and therefore make the variation between titration curves of polyampholytes and the ideal (no electrostatic interactions) curves less significant. We observe that this screening of charge repulsion decreases the chain size. The presence of pearl-necklace configuration of polyampholytes is diminished by the addition of salt. Similar simulations for the polyelectrolyte-polyampholyte system show that the resulting complexes are generally stable in the low pH region. In comparison to ideal case, electrostatic interactions strongly influence the acid-base properties of polyampholyte chains in the adsorbed state by reducing the presence of the coexistence domain of both positive and negative charges in the titration curves. We attribute the complex formation between polyelectrolyte and polyampholyte chains in the high pH region to, e.g., the high salt content. The pH variation leads to abrupt transition between adsorbed and desorbed states. Independent of charge sequence, a polyampholyte chain in a complex is usually located at one of the ends of the polyelectrolyte chain.