A binned Dalitz plot analysis of $B^pm to D K^pm$ decays, with $D to K_S pi^+pi^-$ and $D to K_S K^+ K^-$, is performed to measure the CP-violating observables $x_{pm}$ and $y_{pm}$, which are sensitive to the Cabibbo-Kobayashi-Maskawa angle $gamma$. The analysis exploits a sample of proton-proton collision data corresponding to 3.0invfb collected by the LHCb experiment. Measurements from CLEO-c of the variation of the strong-interaction phase of the $D$ decay over the Dalitz plot are used as inputs. The values of the parameters are found to be $x_+ = (-7.7 pm 2.4 pm 1.0 pm 0.4)times 10^{-2}$, $x_- = (2.5 pm 2.5 pm 1.0 pm 0.5) times 10^{-2}$, $y_+ = (-2.2 pm 2.5 pm 0.4 pm 1.0)times 10^{-2}$, and $y_- = (7.5 pm 2.9 pm 0.5 pm 1.4) times 10^{-2}$. The first, second, and third uncertainties are the statistical, the experimental systematic, and that associated with the precision of the strong-phase parameters. These are the most precise measurements of these observables and correspond to $gamma = (62^{,+15}_{,-14})^circ$, with a second solution at $gamma to gamma + 180^circ$, and $r_B = 0.080^{+ 0.019}_{-0.021}$, where $r_B$ is the ratio between the suppressed and favoured $B$ decay amplitudes.