/**
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⣤⡤⠤⣤⣄⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⡴⠛⠉⠀⠀⠀⠀⠈⠙⢷⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⠟⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⣆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣰⠶⣄⡀⠀⠀⠀⢠⡟⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢹⡆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢰⡏⠀⠀⠉⠛⠶⣤⣸⡇⠀⠀⠀⠀⣀⣤⣶⣶⠒⠒⠒⠶⣬⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⣤⠴⠶⣿⠀⠀⠀⠀⠀⠀⠈⠉⠉⠛⠒⠶⢿⣭⣀⡀⢻⡀⠀⠀⢠⡿⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣤⠶⠛⠋⠁⠀⠀⢸⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠉⠛⠷⣴⣞⠛⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⡴⠞⠉⠀⠀⠀⠀⠀⠀⢰⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠛⢦⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⠞⠋⠀⠀⠀⠀⢀⡤⠠⡄⠀⢰⡏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⠿⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⡞⠁⠀⠀⠀⠀⣠⠖⠋⠀⣸⠇⠀⢸⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⠀⢀⡀⠀⠀⠀⠀⠀⠀⢦⡀⠀⠀⠀⠸⣷⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⡼⠋⠀⠀⠀⠀⢀⣴⠋⢀⢀⡴⠋⠀⢀⣼⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣽⠀⣼⢿⡄⠀⠀⠀⠀⣆⠀⠉⢦⡀⠀⠀⠀⠘⢧⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⡟⠁⠀⠀⠀⠀⣠⠟⠇⠀⠈⠉⠁⠀⣀⣾⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡟⢰⠏⠀⠻⣄⠀⠀⠀⠹⣄⣰⠟⠁⠀⠀⠀⠀⠀⢻⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⣾⡟⠀⢀⣀⡖⠀⣰⠏⠀⠀⠀⠀⠀⢀⣼⣿⠋⠸⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣧⡟⠀⠀⠀⠹⣦⠀⠀⠀⠀⠁⠀⣶⠀⠀⣴⠛⢧⠀⢻⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⣠⠞⣩⡟⠀⠀⠈⠉⠀⢀⡟⠀⠀⢀⣀⣠⣤⣾⡿⠗⠒⠚⣿⠠⣤⠀⠀⠀⠀⠀⠀⠀⢸⣿⠓⠒⠲⠶⠶⠾⢷⣤⣀⣀⠀⠀⠙⣧⠀⠹⣆⣼⠃⠀⢷⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⢀⡴⠟⢁⡼⣿⠁⠀⠀⠀⠀⠀⢸⠃⠀⠀⠈⠉⢠⡾⠋⠀⠀⠀⠀⠸⣆⠙⣧⡀⠀⠀⠀⠀⠀⢸⡇⠀⠀⠀⠀⠀⠀⠀⠻⣆⠉⠁⠀⠀⢹⡄⠀⠈⠁⠀⠀⠘⣷⢦⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⣠⡶⠋⢀⡴⠋⢰⡏⠀⠀⠀⠀⠀⠀⢸⠀⠀⠀⠀⣠⠟⠀⠀⠀⠀⠀⠀⠀⢻⡄⢸⣷⣄⠀⠀⠀⠀⢸⡇⠀⠀⠀⠀⠀⠀⠀⠀⠈⢳⣄⠀⠀⠸⣧⠀⠀⠀⠀⠀⠀⢿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⢰⣾⡥⠴⠞⠋⠀⠀⣼⠀⠀⠀⠀⠀⠀⠀⣸⠀⠀⠀⣰⠏⠀⠀⠀⠀⠀⠀⠀⠀⠀⢻⡄⣷⠙⠷⣄⡀⠀⢸⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⢷⣄⠀⣿⠀⠀⠀⠀⠀⠀⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⣿⡆⠀⠀⠀⠀⠀⠀⢸⡄⠀⣼⢏⣀⣤⣶⣦⣤⣶⣶⣶⣶⣶⣿⣿⣾⡆⠀⠈⠻⢦⣼⡇⢰⣶⣶⣶⣶⣶⣶⣶⣤⣤⣤⣦⠙⢧⣿⠀⠀⠀⠀⠀⠀⢸⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⣿⡇⠀⠀⠀⠀⠀⠀⠘⣇⣼⠏⠘⣿⡿⢿⣿⣿⣿⣿⣿⡏⠉⠉⠉⠙⠃⠀⠀⠀⠀⠉⠁⠘⠛⢻⣿⣿⣿⣿⣿⣟⠛⢛⠷⠀⠀⣿⠀⠀⠀⠀⠀⠀⢸⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⡟⣷⠀⠀⠀⠀⠀⠀⠀⢻⡏⠀⠀⠀⠀⣸⣿⣿⣿⣿⣿⣷⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣾⣿⣿⣿⣿⣿⡇⠀⠀⠀⠀⢰⡏⠀⠀⠀⠀⠀⠀⣾⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⣷⢹⣆⠀⠀⠀⠀⠀⠀⠈⣷⠀⠀⠀⠀⢹⣿⣿⣿⣿⣿⣿⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⠀⣾⠀⠀⠀⠀⠀⠀⢰⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⢿⠘⣿⣆⠀⠀⠀⠀⠀⠐⠘⣧⠀⠀⠀⠘⢿⣿⣿⣿⣿⠏⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⢿⣿⣿⣿⡿⠃⠀⠀⠀⣼⠃⠀⠀⠀⠀⠀⣰⠟⠐⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠸⣇⣿⠙⣧⣄⠀⠀⠀⠀⠀⠘⢧⡀⠀⠀⠈⢹⠿⢟⡋⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⢻⡿⠀⡀⠀⠀⣼⠃⠀⠀⠀⠀⣀⡾⠋⠀⣴⣷⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⢻⣿⠀⣿⠝⠳⣤⣀⡀⠀⠀⠈⢷⣤⠇⢠⡞⠠⠾⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⠟⠁⡾⠃⣠⡾⠃⠀⠀⣀⣤⠾⠋⠀⠀⠀⡿⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⣿⣸⣿⠀⠀⠀⠉⠙⠓⡶⠦⠤⣿⡆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠓⢰⡿⠤⠴⠶⣿⠉⠀⠀⠀⠀⠀⢠⡇⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⣿⢻⠀⠀⠀⠀⠀⠃⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢲⣄⠀⠀⠀⠀⠀⠀⠀⢀⣴⠆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡟⠀⠀⠀⠀⠀⠀⢸⡇⣸⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⡿⢸⡇⠀⠀⠀⠀⠀⢿⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠛⠲⠤⣤⠤⠴⠞⠋⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢰⡏⠀⠀⠀⠀⠀⠀⢸⠇⠈⣇⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣸⡇⢸⡇⠀⠀⠀⠀⠀⢸⣿⣦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢿⡇⠀⠀⠀⠀⠀⠀⢺⢀⠀⢿⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣸⢷⠛⣇⠀⠀⠀⠀⠀⠈⣿⠉⠻⣦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⣾⣅⣸⠀⠀⠀⠀⠀⠀⢀⣿⢸⡀⢸⡇⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡿⠘⣀⣿⠀⠀⠀⠀⠀⢷⢸⡄⠀⠈⠙⠶⣤⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣠⡴⠟⠁⠀⠈⣿⠀⠀⠀⠀⠀⠀⠈⡟⣼⡇⠀⣧⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⢰⡇⠀⢿⢿⠀⠀⠀⠀⠀⠀⠈⣧⠀⠀⠀⠀⠀⠉⠛⠶⢤⣤⣀⣀⠀⣀⡀⠀⠀⠀⠀⠀⢀⣠⡴⠞⠋⠁⠀⠀⠀⠀⢀⡏⠀⠀⠀⠀⠀⠀⢠⡇⢹⣤⠀⢹⡄⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⣼⠀⠀⡿⢸⡆⠀⠀⠀⠀⠀⠀⢻⡆⠀⠀⠀⠀⠀⠀⠀⠀⣿⡿⠟⠋⠉⠁⠀⠀⠀⠀⠀⢸⠁⠀⠀⠀⠀⠀⠀⠀⠀⢸⠇⠀⠀⠀⠀⠀⠀⢸⡇⠈⣟⠀⠈⣷⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⢰⡟⠀⢰⡇⠘⡇⠀⠀⠀⠀⠀⠘⠀⣷⠀⠀⠀⠀⠀⠀⠀⠀⣿⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⡿⠆⠀⠀⠀⠀⠀⠀⣼⠁⠀⢻⡀⠀⠸⣇⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⣼⠁⠀⣼⠁⠀⣿⠀⠀⠀⠀⠀⠀⠀⠻⣇⣀⠀⠀⠀⠀⠀⠀⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⡀⠀⠀⠀⠀⠀⠀⠀⣰⡇⠀⠀⠀⠀⠀⠀⠀⣿⡆⠀⠈⣷⡀⠀⢻⡄⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⢰⡇⠀⢀⡏⠀⠀⢻⠀⠀⠀⠀⠀⠀⠀⠀⢻⣦⣄⠀⠀⠀⠀⣠⡟⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⣧⠀⠀⠀⠀⠀⣠⣾⣿⠀⠀⠀⠀⠀⠀⢠⣠⡇⡇⠀⠀⠸⣯⡀⠀⢷⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⡾⠀⠀⣼⠁⠀⠀⠸⡇⠀⠀⠀⠀⠀⠀⠀⠀⢿⣽⡧⠴⢶⣿⣿⠖⠒⠛⠛⠃⠀⠀⠀⠚⠋⠉⠉⠉⠙⠓⠲⢾⡛⠻⣽⠃⠀⠀⠀⠀⠀⠀⢸⣿⣃⠀⠀⠀⠀⢹⣷⠀⠘⣧⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⣸⠃⠀⢸⡏⠀⠀⠀⢀⣿⠀⠀⠀⠀⢀⣀⠀⠈⠈⢷⠖⠚⠋⠁⢹⡇⠀⢀⣴⠶⠶⢦⣄⣀⣤⡶⠶⠤⠤⠤⠶⠾⠇⢰⡏⠀⠀⠀⠀⠀⠀⠻⣿⣿⣤⡀⠀⠀⠀⠀⢿⣀⠀⠸⣆⠀⠀⠀
⠀⠀⠀⠀⠀⢰⠏⠀⢀⡿⠀⠀⠀⣰⠟⢹⣿⡄⠀⠀⠀⠻⣄⠀⠀⠘⣷⣤⣄⣀⣈⡙⠛⢹⡷⢶⣦⣴⣾⣛⣻⢯⣴⣦⠴⠖⠃⠀⢀⡾⠀⠀⠀⠀⠀⠀⠀⢰⣿⡇⠀⠹⣆⠀⠀⠸⡞⣧⣆⠀⠹⣄⠀⠀
⠀⠀⠀⠀⢠⡟⠀⠀⡼⠁⠀⠀⣰⠏⠀⠈⣟⣧⠀⠀⠀⠀⢻⣆⠀⠀⠈⣧⡿⠀⠈⠉⠛⠛⣻⣿⡿⢿⣿⡍⠉⠀⠀⠀⠀⠀⠀⠀⡾⠁⠀⠀⠀⢀⣴⠀⠀⡾⣿⠁⠀⠀⠘⣧⠀⠀⢿⠘⣟⠀⠀⢻⡄⠀
⠀⠀⢀⣠⡟⠀⢀⡾⠃⠀⠀⣰⡏⠀⠀⠀⣻⠘⣧⠀⠀⠀⠀⢻⣷⡄⠀⠘⢷⡀⠀⠀⠀⠀⠩⣉⠁⠈⣛⡁⠀⠀⠀⠀⠀⠀⣀⣾⠁⠀⠀⣀⣠⣟⠁⠀⣠⣤⡟⠀⠀⠀⠀⠘⣧⡄⠘⡇⠙⣇⠀⠀⠻
*/
#include <bits/stdc++.h>
using namespace std;
#define i64 long long
#define ld long double
#define bit(n,i) ((n>>i)&1)
#define pii pair<int,int>
#define sz(x) (int)x.size()
#define FOR(i,a,b) for(int i=a; i<=b; i++)
#define FOD(i,a,b) for(int i=a; i>=b; i--)
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(),x.end()
#define __sumairu__ main()
#define die_hard_onimai_fan void seggs()
#define file(name) if(fopen(name".inp","r")){freopen(name".inp","r",stdin);freopen(name".out","w",stdout);}
#define brute(name) if(fopen(name".inp","r")){freopen(name".inp","r",stdin);freopen(name".ans","w",stdout);}
#define TIME (1.0*clock()/CLOCKS_PER_SEC)
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ai(n) array<int,n>
#define dbg(x) {cerr<<#x<<' '<<x<<endl;}
#define dbgArr(arr,n) {cerr<<#arr;FOR(_i,1,n)cerr<<' '<<(arr)[_i];cerr<<endl;}
template <typename T,typename U>
ostream& operator<<(ostream &os,pair<T,U>p){
return os<<"{"<<p.fi<<", "<<p.se<<"}";
}
mt19937_64 rd(chrono::steady_clock::now().time_since_epoch().count());
i64 Rand(i64 l,i64 r)
{
i64 ans=l+1ll*rd()*rd()%(r-l+1);
assert(l<=ans&&ans<=r);
return ans;
}
#define i64 long long
#define debug 0
//const i64 base=1e9+7;
//const i64 mod=(1ll<<53)+5;
const int mod=1e9+7;
//const int mod=998244353;
const int inf=1e9;
///check the limits, dummy
const int N=202;
int n,L;
int x[N],t[N];
int dp[N][N][N][2];
int dist(int a,int b)
{
return min((a-b+L)%L,(b-a+L)%L);
}
die_hard_onimai_fan
{
cin>>n>>L;
FOR(i,1,n)cin>>x[i];
FOR(i,1,n)cin>>t[i];
x[n+1]=L,t[n+1]=INT_MAX;
memset(dp,60,sizeof dp);
dp[0][0][0][0]=dp[0][0][0][1]=0;
int ans=0;
FOR(len,0,n)FOR(i,0,len)
{
int j=len-i;
int lim=i+j;
FOR(k,0,lim)
{
FOR(o,0,1)if(dp[i][j][k][o]<1e9)
{
ans=max(ans,k);
int ed=(o?x[n-j+1]:x[i]);
if(i<n)
{
int tmp=dp[i][j][k][o]+dist(ed,x[i+1]);
int nk=k+(tmp<=t[i+1]);
dp[i+1][j][nk][0]=min(dp[i+1][j][nk][0],tmp);
}
if(j<n)
{
int tmp=dp[i][j][k][o]+dist(ed,x[n-j]);
int nk=k+(tmp<=t[n-j]);
dp[i][j+1][nk][1]=min(dp[i][j+1][nk][1],tmp);
}
}
}
}
//FOR(i,0,n)FOR(j,0,n)FOR(k,0,n)FOR(o,0,1)if(dp[i][j][k][o]<inf)cout<<i<<' '<<j<<' '<<k<<' '<<o<<' '<<dp[i][j][k][o]<<'\n';
cout<<ans<<'\n';
}
__sumairu__
{
FAST
file("");
int tt=1;//cin>>tt;
while(tt--)seggs();
cerr<<"\nTime elapsed: "<<TIME<<" s.\n";
}
/**
6 25
3 4 7 17 21 23
11 7 17 10 8 10
*/
Compilation message
ho_t3.cpp:57:21: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
57 | #define __sumairu__ main()
| ^~~~
ho_t3.cpp:140:1: note: in expansion of macro '__sumairu__'
140 | __sumairu__
| ^~~~~~~~~~~
ho_t3.cpp: In function 'int main()':
ho_t3.cpp:59:53: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
59 | #define file(name) if(fopen(name".inp","r")){freopen(name".inp","r",stdin);freopen(name".out","w",stdout);}
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
ho_t3.cpp:143:5: note: in expansion of macro 'file'
143 | file("");
| ^~~~
ho_t3.cpp:59:83: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
59 | #define file(name) if(fopen(name".inp","r")){freopen(name".inp","r",stdin);freopen(name".out","w",stdout);}
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
ho_t3.cpp:143:5: note: in expansion of macro 'file'
143 | file("");
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
64844 KB |
Output is correct |
2 |
Correct |
29 ms |
64860 KB |
Output is correct |
3 |
Correct |
29 ms |
64860 KB |
Output is correct |
4 |
Correct |
29 ms |
64852 KB |
Output is correct |
5 |
Correct |
32 ms |
65104 KB |
Output is correct |
6 |
Correct |
28 ms |
64860 KB |
Output is correct |
7 |
Correct |
31 ms |
64848 KB |
Output is correct |
8 |
Correct |
33 ms |
64848 KB |
Output is correct |
9 |
Correct |
29 ms |
64860 KB |
Output is correct |
10 |
Correct |
27 ms |
64876 KB |
Output is correct |
11 |
Correct |
31 ms |
64868 KB |
Output is correct |
12 |
Correct |
30 ms |
64792 KB |
Output is correct |
13 |
Correct |
28 ms |
64860 KB |
Output is correct |
14 |
Correct |
33 ms |
64860 KB |
Output is correct |
15 |
Correct |
27 ms |
64852 KB |
Output is correct |
16 |
Correct |
30 ms |
64852 KB |
Output is correct |
17 |
Correct |
26 ms |
64988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
64844 KB |
Output is correct |
2 |
Correct |
29 ms |
64860 KB |
Output is correct |
3 |
Correct |
29 ms |
64860 KB |
Output is correct |
4 |
Correct |
29 ms |
64852 KB |
Output is correct |
5 |
Correct |
32 ms |
65104 KB |
Output is correct |
6 |
Correct |
28 ms |
64860 KB |
Output is correct |
7 |
Correct |
31 ms |
64848 KB |
Output is correct |
8 |
Correct |
33 ms |
64848 KB |
Output is correct |
9 |
Correct |
29 ms |
64860 KB |
Output is correct |
10 |
Correct |
27 ms |
64876 KB |
Output is correct |
11 |
Correct |
31 ms |
64868 KB |
Output is correct |
12 |
Correct |
30 ms |
64792 KB |
Output is correct |
13 |
Correct |
28 ms |
64860 KB |
Output is correct |
14 |
Correct |
33 ms |
64860 KB |
Output is correct |
15 |
Correct |
27 ms |
64852 KB |
Output is correct |
16 |
Correct |
30 ms |
64852 KB |
Output is correct |
17 |
Correct |
26 ms |
64988 KB |
Output is correct |
18 |
Correct |
27 ms |
64848 KB |
Output is correct |
19 |
Correct |
30 ms |
64848 KB |
Output is correct |
20 |
Correct |
30 ms |
64856 KB |
Output is correct |
21 |
Correct |
31 ms |
64852 KB |
Output is correct |
22 |
Correct |
26 ms |
64848 KB |
Output is correct |
23 |
Correct |
29 ms |
64808 KB |
Output is correct |
24 |
Correct |
29 ms |
64860 KB |
Output is correct |
25 |
Correct |
31 ms |
64852 KB |
Output is correct |
26 |
Correct |
27 ms |
64936 KB |
Output is correct |
27 |
Correct |
37 ms |
64848 KB |
Output is correct |
28 |
Correct |
31 ms |
64876 KB |
Output is correct |
29 |
Correct |
31 ms |
64716 KB |
Output is correct |
30 |
Correct |
29 ms |
64868 KB |
Output is correct |
31 |
Correct |
31 ms |
64856 KB |
Output is correct |
32 |
Correct |
29 ms |
64860 KB |
Output is correct |
33 |
Correct |
27 ms |
64848 KB |
Output is correct |
34 |
Correct |
29 ms |
64956 KB |
Output is correct |
35 |
Correct |
34 ms |
64716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
64844 KB |
Output is correct |
2 |
Correct |
29 ms |
64860 KB |
Output is correct |
3 |
Correct |
29 ms |
64860 KB |
Output is correct |
4 |
Correct |
29 ms |
64852 KB |
Output is correct |
5 |
Correct |
32 ms |
65104 KB |
Output is correct |
6 |
Correct |
28 ms |
64860 KB |
Output is correct |
7 |
Correct |
31 ms |
64848 KB |
Output is correct |
8 |
Correct |
33 ms |
64848 KB |
Output is correct |
9 |
Correct |
29 ms |
64860 KB |
Output is correct |
10 |
Correct |
27 ms |
64876 KB |
Output is correct |
11 |
Correct |
31 ms |
64868 KB |
Output is correct |
12 |
Correct |
30 ms |
64792 KB |
Output is correct |
13 |
Correct |
28 ms |
64860 KB |
Output is correct |
14 |
Correct |
33 ms |
64860 KB |
Output is correct |
15 |
Correct |
27 ms |
64852 KB |
Output is correct |
16 |
Correct |
30 ms |
64852 KB |
Output is correct |
17 |
Correct |
26 ms |
64988 KB |
Output is correct |
18 |
Correct |
58 ms |
64972 KB |
Output is correct |
19 |
Correct |
42 ms |
64860 KB |
Output is correct |
20 |
Correct |
34 ms |
64892 KB |
Output is correct |
21 |
Correct |
36 ms |
64848 KB |
Output is correct |
22 |
Correct |
46 ms |
64828 KB |
Output is correct |
23 |
Correct |
34 ms |
64852 KB |
Output is correct |
24 |
Correct |
36 ms |
64948 KB |
Output is correct |
25 |
Correct |
32 ms |
64852 KB |
Output is correct |
26 |
Correct |
32 ms |
64944 KB |
Output is correct |
27 |
Correct |
39 ms |
64800 KB |
Output is correct |
28 |
Correct |
31 ms |
64860 KB |
Output is correct |
29 |
Correct |
30 ms |
64852 KB |
Output is correct |
30 |
Correct |
36 ms |
64860 KB |
Output is correct |
31 |
Correct |
34 ms |
64860 KB |
Output is correct |
32 |
Correct |
36 ms |
64852 KB |
Output is correct |
33 |
Correct |
32 ms |
64848 KB |
Output is correct |
34 |
Correct |
30 ms |
64952 KB |
Output is correct |
35 |
Correct |
38 ms |
64952 KB |
Output is correct |
36 |
Correct |
31 ms |
64852 KB |
Output is correct |
37 |
Correct |
29 ms |
64848 KB |
Output is correct |
38 |
Correct |
31 ms |
64964 KB |
Output is correct |
39 |
Correct |
32 ms |
64856 KB |
Output is correct |
40 |
Correct |
35 ms |
64880 KB |
Output is correct |
41 |
Correct |
69 ms |
64908 KB |
Output is correct |
42 |
Correct |
37 ms |
64940 KB |
Output is correct |
43 |
Correct |
66 ms |
64848 KB |
Output is correct |
44 |
Correct |
35 ms |
64940 KB |
Output is correct |
45 |
Correct |
64 ms |
64852 KB |
Output is correct |
46 |
Correct |
38 ms |
64952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
64844 KB |
Output is correct |
2 |
Correct |
29 ms |
64860 KB |
Output is correct |
3 |
Correct |
29 ms |
64860 KB |
Output is correct |
4 |
Correct |
29 ms |
64852 KB |
Output is correct |
5 |
Correct |
32 ms |
65104 KB |
Output is correct |
6 |
Correct |
28 ms |
64860 KB |
Output is correct |
7 |
Correct |
31 ms |
64848 KB |
Output is correct |
8 |
Correct |
33 ms |
64848 KB |
Output is correct |
9 |
Correct |
29 ms |
64860 KB |
Output is correct |
10 |
Correct |
27 ms |
64876 KB |
Output is correct |
11 |
Correct |
31 ms |
64868 KB |
Output is correct |
12 |
Correct |
30 ms |
64792 KB |
Output is correct |
13 |
Correct |
28 ms |
64860 KB |
Output is correct |
14 |
Correct |
33 ms |
64860 KB |
Output is correct |
15 |
Correct |
27 ms |
64852 KB |
Output is correct |
16 |
Correct |
30 ms |
64852 KB |
Output is correct |
17 |
Correct |
26 ms |
64988 KB |
Output is correct |
18 |
Correct |
27 ms |
64848 KB |
Output is correct |
19 |
Correct |
30 ms |
64848 KB |
Output is correct |
20 |
Correct |
30 ms |
64856 KB |
Output is correct |
21 |
Correct |
31 ms |
64852 KB |
Output is correct |
22 |
Correct |
26 ms |
64848 KB |
Output is correct |
23 |
Correct |
29 ms |
64808 KB |
Output is correct |
24 |
Correct |
29 ms |
64860 KB |
Output is correct |
25 |
Correct |
31 ms |
64852 KB |
Output is correct |
26 |
Correct |
27 ms |
64936 KB |
Output is correct |
27 |
Correct |
37 ms |
64848 KB |
Output is correct |
28 |
Correct |
31 ms |
64876 KB |
Output is correct |
29 |
Correct |
31 ms |
64716 KB |
Output is correct |
30 |
Correct |
29 ms |
64868 KB |
Output is correct |
31 |
Correct |
31 ms |
64856 KB |
Output is correct |
32 |
Correct |
29 ms |
64860 KB |
Output is correct |
33 |
Correct |
27 ms |
64848 KB |
Output is correct |
34 |
Correct |
29 ms |
64956 KB |
Output is correct |
35 |
Correct |
34 ms |
64716 KB |
Output is correct |
36 |
Correct |
58 ms |
64972 KB |
Output is correct |
37 |
Correct |
42 ms |
64860 KB |
Output is correct |
38 |
Correct |
34 ms |
64892 KB |
Output is correct |
39 |
Correct |
36 ms |
64848 KB |
Output is correct |
40 |
Correct |
46 ms |
64828 KB |
Output is correct |
41 |
Correct |
34 ms |
64852 KB |
Output is correct |
42 |
Correct |
36 ms |
64948 KB |
Output is correct |
43 |
Correct |
32 ms |
64852 KB |
Output is correct |
44 |
Correct |
32 ms |
64944 KB |
Output is correct |
45 |
Correct |
39 ms |
64800 KB |
Output is correct |
46 |
Correct |
31 ms |
64860 KB |
Output is correct |
47 |
Correct |
30 ms |
64852 KB |
Output is correct |
48 |
Correct |
36 ms |
64860 KB |
Output is correct |
49 |
Correct |
34 ms |
64860 KB |
Output is correct |
50 |
Correct |
36 ms |
64852 KB |
Output is correct |
51 |
Correct |
32 ms |
64848 KB |
Output is correct |
52 |
Correct |
30 ms |
64952 KB |
Output is correct |
53 |
Correct |
38 ms |
64952 KB |
Output is correct |
54 |
Correct |
31 ms |
64852 KB |
Output is correct |
55 |
Correct |
29 ms |
64848 KB |
Output is correct |
56 |
Correct |
31 ms |
64964 KB |
Output is correct |
57 |
Correct |
32 ms |
64856 KB |
Output is correct |
58 |
Correct |
35 ms |
64880 KB |
Output is correct |
59 |
Correct |
69 ms |
64908 KB |
Output is correct |
60 |
Correct |
37 ms |
64940 KB |
Output is correct |
61 |
Correct |
66 ms |
64848 KB |
Output is correct |
62 |
Correct |
35 ms |
64940 KB |
Output is correct |
63 |
Correct |
64 ms |
64852 KB |
Output is correct |
64 |
Correct |
38 ms |
64952 KB |
Output is correct |
65 |
Correct |
42 ms |
64952 KB |
Output is correct |
66 |
Correct |
40 ms |
64860 KB |
Output is correct |
67 |
Correct |
40 ms |
64852 KB |
Output is correct |
68 |
Correct |
39 ms |
64856 KB |
Output is correct |
69 |
Correct |
44 ms |
64860 KB |
Output is correct |
70 |
Correct |
42 ms |
64856 KB |
Output is correct |
71 |
Correct |
38 ms |
64860 KB |
Output is correct |
72 |
Correct |
40 ms |
64924 KB |
Output is correct |
73 |
Correct |
43 ms |
64856 KB |
Output is correct |
74 |
Correct |
53 ms |
64848 KB |
Output is correct |
75 |
Correct |
41 ms |
64852 KB |
Output is correct |
76 |
Correct |
64 ms |
64860 KB |
Output is correct |
77 |
Correct |
40 ms |
64936 KB |
Output is correct |
78 |
Correct |
50 ms |
64860 KB |
Output is correct |
79 |
Correct |
40 ms |
64784 KB |
Output is correct |
80 |
Correct |
62 ms |
64860 KB |
Output is correct |
81 |
Correct |
40 ms |
64856 KB |
Output is correct |
82 |
Correct |
48 ms |
64856 KB |
Output is correct |
83 |
Correct |
48 ms |
64852 KB |
Output is correct |
84 |
Correct |
52 ms |
64860 KB |
Output is correct |
85 |
Correct |
67 ms |
64848 KB |
Output is correct |
86 |
Correct |
52 ms |
64852 KB |
Output is correct |
87 |
Correct |
39 ms |
64848 KB |
Output is correct |
88 |
Correct |
55 ms |
64716 KB |
Output is correct |
89 |
Correct |
40 ms |
64860 KB |
Output is correct |
90 |
Correct |
38 ms |
64860 KB |
Output is correct |
91 |
Correct |
59 ms |
64852 KB |
Output is correct |
92 |
Correct |
44 ms |
64856 KB |
Output is correct |
93 |
Correct |
40 ms |
64860 KB |
Output is correct |