The AF500FTZ is a nice flash but won't work very well with either of these cameras. Only a few of its features work; the cameras don't have a sensor required for automatic exposure. For full compatibility, you want a P-TTL flash. There's a complete feference here:
https://www.pentaxforums.com/forums/pentax-camera-field-accessories/43215-pen...omparison.html
The AF360FGZ is compatible, and the replacement for the AF500FTZ is the AF540FGZ, also compatible with more features and power than the 360. The K-x can do a bit more with these flashes than the DL, especially wireless.