# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
989488 |
2024-05-28T08:35:45 Z |
hahahaha |
Feast (NOI19_feast) |
C++17 |
|
96 ms |
12820 KB |
/**
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⣤⡤⠤⣤⣄⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⡴⠛⠉⠀⠀⠀⠀⠈⠙⢷⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⠟⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⣆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣰⠶⣄⡀⠀⠀⠀⢠⡟⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢹⡆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢰⡏⠀⠀⠉⠛⠶⣤⣸⡇⠀⠀⠀⠀⣀⣤⣶⣶⠒⠒⠒⠶⣬⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⣤⠴⠶⣿⠀⠀⠀⠀⠀⠀⠈⠉⠉⠛⠒⠶⢿⣭⣀⡀⢻⡀⠀⠀⢠⡿⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣤⠶⠛⠋⠁⠀⠀⢸⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠉⠛⠷⣴⣞⠛⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⡴⠞⠉⠀⠀⠀⠀⠀⠀⢰⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠛⢦⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⠞⠋⠀⠀⠀⠀⢀⡤⠠⡄⠀⢰⡏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⠿⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⡞⠁⠀⠀⠀⠀⣠⠖⠋⠀⣸⠇⠀⢸⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⠀⢀⡀⠀⠀⠀⠀⠀⠀⢦⡀⠀⠀⠀⠸⣷⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⡼⠋⠀⠀⠀⠀⢀⣴⠋⢀⢀⡴⠋⠀⢀⣼⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣽⠀⣼⢿⡄⠀⠀⠀⠀⣆⠀⠉⢦⡀⠀⠀⠀⠘⢧⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⡟⠁⠀⠀⠀⠀⣠⠟⠇⠀⠈⠉⠁⠀⣀⣾⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡟⢰⠏⠀⠻⣄⠀⠀⠀⠹⣄⣰⠟⠁⠀⠀⠀⠀⠀⢻⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⣾⡟⠀⢀⣀⡖⠀⣰⠏⠀⠀⠀⠀⠀⢀⣼⣿⠋⠸⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣧⡟⠀⠀⠀⠹⣦⠀⠀⠀⠀⠁⠀⣶⠀⠀⣴⠛⢧⠀⢻⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⣠⠞⣩⡟⠀⠀⠈⠉⠀⢀⡟⠀⠀⢀⣀⣠⣤⣾⡿⠗⠒⠚⣿⠠⣤⠀⠀⠀⠀⠀⠀⠀⢸⣿⠓⠒⠲⠶⠶⠾⢷⣤⣀⣀⠀⠀⠙⣧⠀⠹⣆⣼⠃⠀⢷⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⢀⡴⠟⢁⡼⣿⠁⠀⠀⠀⠀⠀⢸⠃⠀⠀⠈⠉⢠⡾⠋⠀⠀⠀⠀⠸⣆⠙⣧⡀⠀⠀⠀⠀⠀⢸⡇⠀⠀⠀⠀⠀⠀⠀⠻⣆⠉⠁⠀⠀⢹⡄⠀⠈⠁⠀⠀⠘⣷⢦⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⣠⡶⠋⢀⡴⠋⢰⡏⠀⠀⠀⠀⠀⠀⢸⠀⠀⠀⠀⣠⠟⠀⠀⠀⠀⠀⠀⠀⢻⡄⢸⣷⣄⠀⠀⠀⠀⢸⡇⠀⠀⠀⠀⠀⠀⠀⠀⠈⢳⣄⠀⠀⠸⣧⠀⠀⠀⠀⠀⠀⢿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⢰⣾⡥⠴⠞⠋⠀⠀⣼⠀⠀⠀⠀⠀⠀⠀⣸⠀⠀⠀⣰⠏⠀⠀⠀⠀⠀⠀⠀⠀⠀⢻⡄⣷⠙⠷⣄⡀⠀⢸⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⢷⣄⠀⣿⠀⠀⠀⠀⠀⠀⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⣿⡆⠀⠀⠀⠀⠀⠀⢸⡄⠀⣼⢏⣀⣤⣶⣦⣤⣶⣶⣶⣶⣶⣿⣿⣾⡆⠀⠈⠻⢦⣼⡇⢰⣶⣶⣶⣶⣶⣶⣶⣤⣤⣤⣦⠙⢧⣿⠀⠀⠀⠀⠀⠀⢸⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⣿⡇⠀⠀⠀⠀⠀⠀⠘⣇⣼⠏⠘⣿⡿⢿⣿⣿⣿⣿⣿⡏⠉⠉⠉⠙⠃⠀⠀⠀⠀⠉⠁⠘⠛⢻⣿⣿⣿⣿⣿⣟⠛⢛⠷⠀⠀⣿⠀⠀⠀⠀⠀⠀⢸⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⡟⣷⠀⠀⠀⠀⠀⠀⠀⢻⡏⠀⠀⠀⠀⣸⣿⣿⣿⣿⣿⣷⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣾⣿⣿⣿⣿⣿⡇⠀⠀⠀⠀⢰⡏⠀⠀⠀⠀⠀⠀⣾⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⣷⢹⣆⠀⠀⠀⠀⠀⠀⠈⣷⠀⠀⠀⠀⢹⣿⣿⣿⣿⣿⣿⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⠀⣾⠀⠀⠀⠀⠀⠀⢰⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⢿⠘⣿⣆⠀⠀⠀⠀⠀⠐⠘⣧⠀⠀⠀⠘⢿⣿⣿⣿⣿⠏⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⢿⣿⣿⣿⡿⠃⠀⠀⠀⣼⠃⠀⠀⠀⠀⠀⣰⠟⠐⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠸⣇⣿⠙⣧⣄⠀⠀⠀⠀⠀⠘⢧⡀⠀⠀⠈⢹⠿⢟⡋⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⢻⡿⠀⡀⠀⠀⣼⠃⠀⠀⠀⠀⣀⡾⠋⠀⣴⣷⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⢻⣿⠀⣿⠝⠳⣤⣀⡀⠀⠀⠈⢷⣤⠇⢠⡞⠠⠾⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⠟⠁⡾⠃⣠⡾⠃⠀⠀⣀⣤⠾⠋⠀⠀⠀⡿⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⣿⣸⣿⠀⠀⠀⠉⠙⠓⡶⠦⠤⣿⡆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠓⢰⡿⠤⠴⠶⣿⠉⠀⠀⠀⠀⠀⢠⡇⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⣿⢻⠀⠀⠀⠀⠀⠃⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢲⣄⠀⠀⠀⠀⠀⠀⠀⢀⣴⠆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡟⠀⠀⠀⠀⠀⠀⢸⡇⣸⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⡿⢸⡇⠀⠀⠀⠀⠀⢿⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠛⠲⠤⣤⠤⠴⠞⠋⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢰⡏⠀⠀⠀⠀⠀⠀⢸⠇⠈⣇⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣸⡇⢸⡇⠀⠀⠀⠀⠀⢸⣿⣦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢿⡇⠀⠀⠀⠀⠀⠀⢺⢀⠀⢿⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣸⢷⠛⣇⠀⠀⠀⠀⠀⠈⣿⠉⠻⣦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⣾⣅⣸⠀⠀⠀⠀⠀⠀⢀⣿⢸⡀⢸⡇⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡿⠘⣀⣿⠀⠀⠀⠀⠀⢷⢸⡄⠀⠈⠙⠶⣤⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣠⡴⠟⠁⠀⠈⣿⠀⠀⠀⠀⠀⠀⠈⡟⣼⡇⠀⣧⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⢰⡇⠀⢿⢿⠀⠀⠀⠀⠀⠀⠈⣧⠀⠀⠀⠀⠀⠉⠛⠶⢤⣤⣀⣀⠀⣀⡀⠀⠀⠀⠀⠀⢀⣠⡴⠞⠋⠁⠀⠀⠀⠀⢀⡏⠀⠀⠀⠀⠀⠀⢠⡇⢹⣤⠀⢹⡄⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⣼⠀⠀⡿⢸⡆⠀⠀⠀⠀⠀⠀⢻⡆⠀⠀⠀⠀⠀⠀⠀⠀⣿⡿⠟⠋⠉⠁⠀⠀⠀⠀⠀⢸⠁⠀⠀⠀⠀⠀⠀⠀⠀⢸⠇⠀⠀⠀⠀⠀⠀⢸⡇⠈⣟⠀⠈⣷⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⢰⡟⠀⢰⡇⠘⡇⠀⠀⠀⠀⠀⠘⠀⣷⠀⠀⠀⠀⠀⠀⠀⠀⣿⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⡿⠆⠀⠀⠀⠀⠀⠀⣼⠁⠀⢻⡀⠀⠸⣇⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⣼⠁⠀⣼⠁⠀⣿⠀⠀⠀⠀⠀⠀⠀⠻⣇⣀⠀⠀⠀⠀⠀⠀⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⡀⠀⠀⠀⠀⠀⠀⠀⣰⡇⠀⠀⠀⠀⠀⠀⠀⣿⡆⠀⠈⣷⡀⠀⢻⡄⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⢰⡇⠀⢀⡏⠀⠀⢻⠀⠀⠀⠀⠀⠀⠀⠀⢻⣦⣄⠀⠀⠀⠀⣠⡟⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⣧⠀⠀⠀⠀⠀⣠⣾⣿⠀⠀⠀⠀⠀⠀⢠⣠⡇⡇⠀⠀⠸⣯⡀⠀⢷⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⡾⠀⠀⣼⠁⠀⠀⠸⡇⠀⠀⠀⠀⠀⠀⠀⠀⢿⣽⡧⠴⢶⣿⣿⠖⠒⠛⠛⠃⠀⠀⠀⠚⠋⠉⠉⠉⠙⠓⠲⢾⡛⠻⣽⠃⠀⠀⠀⠀⠀⠀⢸⣿⣃⠀⠀⠀⠀⢹⣷⠀⠘⣧⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⣸⠃⠀⢸⡏⠀⠀⠀⢀⣿⠀⠀⠀⠀⢀⣀⠀⠈⠈⢷⠖⠚⠋⠁⢹⡇⠀⢀⣴⠶⠶⢦⣄⣀⣤⡶⠶⠤⠤⠤⠶⠾⠇⢰⡏⠀⠀⠀⠀⠀⠀⠻⣿⣿⣤⡀⠀⠀⠀⠀⢿⣀⠀⠸⣆⠀⠀⠀
⠀⠀⠀⠀⠀⢰⠏⠀⢀⡿⠀⠀⠀⣰⠟⢹⣿⡄⠀⠀⠀⠻⣄⠀⠀⠘⣷⣤⣄⣀⣈⡙⠛⢹⡷⢶⣦⣴⣾⣛⣻⢯⣴⣦⠴⠖⠃⠀⢀⡾⠀⠀⠀⠀⠀⠀⠀⢰⣿⡇⠀⠹⣆⠀⠀⠸⡞⣧⣆⠀⠹⣄⠀⠀
⠀⠀⠀⠀⢠⡟⠀⠀⡼⠁⠀⠀⣰⠏⠀⠈⣟⣧⠀⠀⠀⠀⢻⣆⠀⠀⠈⣧⡿⠀⠈⠉⠛⠛⣻⣿⡿⢿⣿⡍⠉⠀⠀⠀⠀⠀⠀⠀⡾⠁⠀⠀⠀⢀⣴⠀⠀⡾⣿⠁⠀⠀⠘⣧⠀⠀⢿⠘⣟⠀⠀⢻⡄⠀
⠀⠀⢀⣠⡟⠀⢀⡾⠃⠀⠀⣰⡏⠀⠀⠀⣻⠘⣧⠀⠀⠀⠀⢻⣷⡄⠀⠘⢷⡀⠀⠀⠀⠀⠩⣉⠁⠈⣛⡁⠀⠀⠀⠀⠀⠀⣀⣾⠁⠀⠀⣀⣠⣟⠁⠀⣠⣤⡟⠀⠀⠀⠀⠘⣧⡄⠘⡇⠙⣇⠀⠀⠻
*/
#include <bits/stdc++.h>
#define i64 long long
#define ld long double
#define bit(n,i) ((n>>i)&1)
#define mp make_pair
#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 i_love_flandre_scarlet 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>
using namespace std;
const int MOD=998244353;
//const int MOD=1e9+7;
const int inf=1e9;
mt19937_64 rd(chrono::steady_clock::now().time_since_epoch().count());
///check the limits, dummy
const int N=3e5+5;
#define int long long
int n,k;
int a[N];
i64 pre[N];
namespace sub1
{
bool check(){return n<=2000&&k<=2000;}
i64 t[2003][2003*4];
void up(int c,int id,int l,int r,int p,i64 v)
{
if(p>r||p<l)return;
if(l==r)
{
t[c][id]=v;
return;
}
int m=(l+r)/2;
up(c,id*2,l,m,p,v);
up(c,id*2+1,m+1,r,p,v);
t[c][id]=max(t[c][id*2],t[c][id*2+1]);
}
i64 get(int c,int id,int l,int r,int x,int y)
{
if(x>r||y<l)return -1e18;
if(x<=l&&r<=y)return t[c][id];
int m=(l+r)/2;
return max(get(c,id*2,l,m,x,y),get(c,id*2+1,m+1,r,x,y));
}
void solve()
{
vector<vector<i64>>dp(n+1,vector<i64>(k+1));
/**
dp[i][j]: up to i, picked j segments
dp[i][j] = dp[k][j-1]+sum(k+1,i) = ...+t[i]-t[k]
(take i)dp[i][j] = t[i] + dp[k][j-1] - t[k] (k<i)
(not take i)dp[i][j] = dp[k][j]
*/
memset(t,-60,sizeof t);
i64 ans=0;
if(k==1)ans=max(ans,1ll*a[1]);
FOR(i,0,n)up(0,1,0,n,i,0-pre[i]);
vector<vector<i64>>preMx(k+1,vector<i64>(n+1));
FOR(i,1,n)
{
FOD(j,min(k,i),1)
{
dp[i][j]=max(dp[i][j],pre[i]+get(j-1,1,0,n,0,i-1));
dp[i][j]=max(dp[i][j],preMx[j][i-1]);
up(j,1,0,n,i,dp[i][j]-pre[i]);
preMx[j][i]=max(preMx[j][i-1],dp[i][j]);
}
ans=max(ans,dp[i][k]);
}
// FOR(i,1,n)
// {
// FOR(j,1,k)if(dp[i][j]!=-1e18)
// {
// cout<<i<<' '<<j<<' '<<dp[i][j]<<'\n';
// }
// }
cout<<ans;
exit(0);
}
}
namespace sub2
{
bool check(){return 1;}
pii dp[N];
pii check(int x)
{
memset(dp,0,sizeof(dp));
pii ans{};
FOR(i,0,n-1)
{
pii tmp{dp[i].first-pre[i], dp[i].second};
if(tmp.fi^ans.fi?tmp.fi>ans.fi:tmp.se<ans.se)ans=tmp;
pii tmp2{ans.fi-x+pre[i+1],ans.se+1};
dp[i+1]=(tmp2.fi^dp[i].fi?tmp2.fi>dp[i].fi:tmp2.se<dp[i].se)?tmp2:dp[i];
}
return dp[n];
}
void solve()
{
FOR(i,1,n)a[i]+=a[i-1];
int l=0,r=3e14;
while(l<r)
{
int mid=(l+r)/2;
if(check(mid).se<=k)r=mid;
else l=mid+1;
}
pii ans=check(l);
cout<<ans.fi+k*l;
exit(0);
}
}
i_love_flandre_scarlet
{
cin>>n>>k;
FOR(i,1,n)
{
cin>>a[i];
pre[i]=pre[i-1]+a[i];
}
if(*min_element(a+1,a+n+1)>=0)
{
i64 ans=0;
FOR(i,1,n)ans+=a[i];
cout<<ans;
return;
}
int cnt=0;
FOR(i,1,n)cnt+=(a[i]<0);
if(cnt==1)
{
i64 L=0,R=0;
FOR(i,1,n)if(a[i]<0)
{
L=pre[i-1];
R=pre[n]-pre[i];
}
if(k>=2)cout<<L+R;
else cout<<max(L,R);
return;
}
if(sub2::check())sub2::solve();
if(sub1::check())sub1::solve();
}
__sumairu__
{
FAST
//file("ぺぽよ⋆PEPOYO");
// freopen("feas.inp","r",stdin);
// freopen("feas.out","w",stdout);
int t=1;//cin>>t;
while(t--)seggs();
//cerr<<"\nTime elapsed: "<<TIME<<" s.\n";
}
/**
6 1
1 -2 3 -1 5 -6
6 2
1 2 3 -10 5 6
6 4
-1 -2 -1 0 -5 -1
*/
Compilation message
feast.cpp: In function 'std::pair<long long int, long long int> sub2::check(long long int)':
feast.cpp:156:31: warning: 'void* memset(void*, int, size_t)' clearing an object of type 'struct std::pair<long long int, long long int>' with no trivial copy-assignment; use assignment instead [-Wclass-memaccess]
156 | memset(dp,0,sizeof(dp));
| ^
In file included from /usr/include/c++/10/bits/stl_algobase.h:64,
from /usr/include/c++/10/bits/specfun.h:45,
from /usr/include/c++/10/cmath:1927,
from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
from feast.cpp:43:
/usr/include/c++/10/bits/stl_pair.h:211:12: note: 'struct std::pair<long long int, long long int>' declared here
211 | struct pair
| ^~~~
feast.cpp: At global scope:
feast.cpp:56:21: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
56 | #define __sumairu__ main()
| ^~~~
feast.cpp:224:1: note: in expansion of macro '__sumairu__'
224 | __sumairu__
| ^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
5604 KB |
Output is correct |
2 |
Correct |
21 ms |
7808 KB |
Output is correct |
3 |
Correct |
27 ms |
7956 KB |
Output is correct |
4 |
Correct |
24 ms |
7896 KB |
Output is correct |
5 |
Correct |
25 ms |
7812 KB |
Output is correct |
6 |
Correct |
23 ms |
7676 KB |
Output is correct |
7 |
Correct |
30 ms |
7680 KB |
Output is correct |
8 |
Correct |
25 ms |
7924 KB |
Output is correct |
9 |
Correct |
27 ms |
7764 KB |
Output is correct |
10 |
Correct |
29 ms |
7768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
5140 KB |
Output is correct |
2 |
Incorrect |
15 ms |
6236 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
71 ms |
10548 KB |
Output is correct |
2 |
Correct |
56 ms |
12716 KB |
Output is correct |
3 |
Correct |
60 ms |
12792 KB |
Output is correct |
4 |
Correct |
55 ms |
12584 KB |
Output is correct |
5 |
Correct |
56 ms |
12560 KB |
Output is correct |
6 |
Correct |
54 ms |
12636 KB |
Output is correct |
7 |
Correct |
59 ms |
12684 KB |
Output is correct |
8 |
Correct |
96 ms |
12820 KB |
Output is correct |
9 |
Correct |
69 ms |
12680 KB |
Output is correct |
10 |
Correct |
92 ms |
12760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
7000 KB |
Output is correct |
2 |
Correct |
8 ms |
4956 KB |
Output is correct |
3 |
Correct |
8 ms |
4956 KB |
Output is correct |
4 |
Correct |
7 ms |
4956 KB |
Output is correct |
5 |
Correct |
9 ms |
5084 KB |
Output is correct |
6 |
Correct |
7 ms |
7016 KB |
Output is correct |
7 |
Correct |
8 ms |
5176 KB |
Output is correct |
8 |
Correct |
7 ms |
5180 KB |
Output is correct |
9 |
Correct |
9 ms |
4952 KB |
Output is correct |
10 |
Correct |
8 ms |
4956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
7000 KB |
Output is correct |
2 |
Correct |
8 ms |
4956 KB |
Output is correct |
3 |
Correct |
8 ms |
4956 KB |
Output is correct |
4 |
Correct |
7 ms |
4956 KB |
Output is correct |
5 |
Correct |
9 ms |
5084 KB |
Output is correct |
6 |
Correct |
7 ms |
7016 KB |
Output is correct |
7 |
Correct |
8 ms |
5176 KB |
Output is correct |
8 |
Correct |
7 ms |
5180 KB |
Output is correct |
9 |
Correct |
9 ms |
4952 KB |
Output is correct |
10 |
Correct |
8 ms |
4956 KB |
Output is correct |
11 |
Correct |
7 ms |
7000 KB |
Output is correct |
12 |
Correct |
8 ms |
7004 KB |
Output is correct |
13 |
Correct |
7 ms |
7004 KB |
Output is correct |
14 |
Correct |
7 ms |
7004 KB |
Output is correct |
15 |
Correct |
7 ms |
7004 KB |
Output is correct |
16 |
Correct |
8 ms |
7004 KB |
Output is correct |
17 |
Correct |
8 ms |
6984 KB |
Output is correct |
18 |
Correct |
8 ms |
7228 KB |
Output is correct |
19 |
Correct |
7 ms |
7004 KB |
Output is correct |
20 |
Correct |
9 ms |
7004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
7000 KB |
Output is correct |
2 |
Correct |
8 ms |
4956 KB |
Output is correct |
3 |
Correct |
8 ms |
4956 KB |
Output is correct |
4 |
Correct |
7 ms |
4956 KB |
Output is correct |
5 |
Correct |
9 ms |
5084 KB |
Output is correct |
6 |
Correct |
7 ms |
7016 KB |
Output is correct |
7 |
Correct |
8 ms |
5176 KB |
Output is correct |
8 |
Correct |
7 ms |
5180 KB |
Output is correct |
9 |
Correct |
9 ms |
4952 KB |
Output is correct |
10 |
Correct |
8 ms |
4956 KB |
Output is correct |
11 |
Correct |
7 ms |
7000 KB |
Output is correct |
12 |
Correct |
8 ms |
7004 KB |
Output is correct |
13 |
Correct |
7 ms |
7004 KB |
Output is correct |
14 |
Correct |
7 ms |
7004 KB |
Output is correct |
15 |
Correct |
7 ms |
7004 KB |
Output is correct |
16 |
Correct |
8 ms |
7004 KB |
Output is correct |
17 |
Correct |
8 ms |
6984 KB |
Output is correct |
18 |
Correct |
8 ms |
7228 KB |
Output is correct |
19 |
Correct |
7 ms |
7004 KB |
Output is correct |
20 |
Correct |
9 ms |
7004 KB |
Output is correct |
21 |
Correct |
9 ms |
4956 KB |
Output is correct |
22 |
Correct |
9 ms |
4956 KB |
Output is correct |
23 |
Correct |
8 ms |
7004 KB |
Output is correct |
24 |
Correct |
8 ms |
7004 KB |
Output is correct |
25 |
Correct |
7 ms |
4952 KB |
Output is correct |
26 |
Correct |
7 ms |
4956 KB |
Output is correct |
27 |
Correct |
8 ms |
5208 KB |
Output is correct |
28 |
Correct |
9 ms |
4956 KB |
Output is correct |
29 |
Correct |
8 ms |
4956 KB |
Output is correct |
30 |
Correct |
7 ms |
5100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
5604 KB |
Output is correct |
2 |
Correct |
21 ms |
7808 KB |
Output is correct |
3 |
Correct |
27 ms |
7956 KB |
Output is correct |
4 |
Correct |
24 ms |
7896 KB |
Output is correct |
5 |
Correct |
25 ms |
7812 KB |
Output is correct |
6 |
Correct |
23 ms |
7676 KB |
Output is correct |
7 |
Correct |
30 ms |
7680 KB |
Output is correct |
8 |
Correct |
25 ms |
7924 KB |
Output is correct |
9 |
Correct |
27 ms |
7764 KB |
Output is correct |
10 |
Correct |
29 ms |
7768 KB |
Output is correct |
11 |
Correct |
13 ms |
5140 KB |
Output is correct |
12 |
Incorrect |
15 ms |
6236 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |