diff options
| author | omagdy7 <omar.professional8777@gmail.com> | 2023-03-19 11:58:33 +0200 |
|---|---|---|
| committer | omagdy7 <omar.professional8777@gmail.com> | 2023-03-19 11:58:33 +0200 |
| commit | ba391960d9d26180335fccc2f3d593021324de76 (patch) | |
| tree | 7fb520af7ba4ff0b56a2e67282bf8c3f686fb36d /codeforces/CormenTheBestFriendOfAMan/main.cpp | |
| parent | ef09dc1158cfb989a59af5e987d1791d159ad055 (diff) | |
| download | competitive-programming-ba391960d9d26180335fccc2f3d593021324de76.tar.xz competitive-programming-ba391960d9d26180335fccc2f3d593021324de76.zip | |
Solved new problems from codeforces
Diffstat (limited to 'codeforces/CormenTheBestFriendOfAMan/main.cpp')
| -rwxr-xr-x | codeforces/CormenTheBestFriendOfAMan/main.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/codeforces/CormenTheBestFriendOfAMan/main.cpp b/codeforces/CormenTheBestFriendOfAMan/main.cpp index 25db2b2..4e41dad 100755 --- a/codeforces/CormenTheBestFriendOfAMan/main.cpp +++ b/codeforces/CormenTheBestFriendOfAMan/main.cpp @@ -22,10 +22,27 @@ const db PI = acos((db)-1); const int dx[4]{1, 0, -1, 0}; const int dy[4]{0, 1, 0, -1}; +// v[i + 1] + v[i] = k + void solve() { int n, k; cin >> n >> k; vi v(n); + for (auto &x : v) cin >> x; + vi ans(n); + int cnt = 0; + for (int i = 0; i < n - 1; i++) { + if (v[i] + v[i + 1] < k) { + int aw = k - v[i]; + cnt += aw - v[i + 1]; + v[i + 1] = aw; + } + } + cout << cnt << '\n'; + for (auto x : v) { + cout << x << ' '; + } + cout << '\n'; } |
