G. FacePalm Accounting

Codeforces
IDCF10051G
Time1000ms
Memory512MB
Difficulty
English · Original
Formal · Original
An owner of a small company FacePalm has recently learned that the city authorities plan to offer to small businesses to participate in improving parks and garden squares. However, credible sources informed the FacePalm owner that the loss-making companies will not get such an offer. Moreover, the sources have also told how loss-making companies will be determined. A company will be considered _loss-making_ if for every k contiguous days the total income of the company is negative. The FacePalm owner discussed the situation with his chief accountant, and they decided to change the report so that the company would look loss-making. The company report for n days can be represented as a sequence of integers a1, a2, ..., an, where ai is the company income in the day i (negative values correspond to losses). The accountant can change any values in this sequence, but no updated value can become less than the smallest value in the original report — otherwise the updated report will look absolutely implausible. Besides, the accountant wants the total change of the values to be as small as possible. We will assume that the total change of the values is , where is the i-th value in the updated report. Your task is to calculate the minimum required total change of the values and provide the updated report. The first line contains integers n and k (1 ≤ k ≤ n ≤ 2·105) — the number of days in the report and the number of days in the definition of loss-making company. The second line contains n space-separated integers a1, a2, ..., an ( - 10000 ≤ ai ≤ 10000), where ai is the company income in day i. It is guaranteed that at least one value of ai is negative. In the first line print the required minimum total change. In the second line print the corresponding updated report. No value in the updated report can be less than the minimum value of the original report. If there are multiple solutions, print any of them. ## Input The first line contains integers n and k (1 ≤ k ≤ n ≤ 2·105) — the number of days in the report and the number of days in the definition of loss-making company. The second line contains n space-separated integers a1, a2, ..., an ( - 10000 ≤ ai ≤ 10000), where ai is the company income in day i.It is guaranteed that at least one value of ai is negative. ## Output In the first line print the required minimum total change. In the second line print the corresponding updated report. No value in the updated report can be less than the minimum value of the original report.If there are multiple solutions, print any of them. [samples]
**Definitions** Let $ S \in \{\texttt{\#cf\_span[}w\texttt{]}\} $ be the input string, where $ w \in \Sigma^* $ is a substring of lowercase letters. Let $ D: \Sigma^* \to \Sigma^* $ be the decryption function such that $ D(\texttt{\#cf\_span[}w\texttt{]}) = s $, where $ s $ is the original English string. **Given** - $ D(\texttt{\#cf\_span[eczhrah]}) = \texttt{cheshire} $ - $ D(\texttt{\#cf\_span[ytmomeufsi]}) = \texttt{symmetry} $ **Objective** For each of the 7 input strings, compute $ s = D(w) $, where $ w $ is the inner substring of $ \texttt{\#cf\_span[}w\texttt{]} $, and output $ s $.
API Response (JSON)
{
  "problem": {
    "name": "G. FacePalm Accounting",
    "description": {
      "content": "An owner of a small company FacePalm has recently learned that the city authorities plan to offer to small businesses to participate in improving parks and garden squares. However, credible sources in",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 524288
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10051G"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "An owner of a small company FacePalm has recently learned that the city authorities plan to offer to small businesses to participate in improving parks and garden squares. However, credible sources in...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ S \\in \\{\\texttt{\\#cf\\_span[}w\\texttt{]}\\} $ be the input string, where $ w \\in \\Sigma^* $ is a substring of lowercase letters.  \nLet $ D: \\Sigma^* \\to \\Sigma^* $ be the decrypt...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments