|
|
back to boardWrong answer. Help pls!! C++ #include <iostream> using namespace std; int main() { int n, k, *arr,raz,y=0,ost=0; cin >> n >> k; arr = new int[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; } for (int i = 0; i < n; i++) { raz = 5 - arr[i]; if (raz >= 0) { y = y + raz; } else { y = y; ost = ost + raz * -1; } } cout << ost << " " << y; return 0; } Re: Wrong answer. Help pls!! C++ > raz = 5 - arr[i]; Why "5" ? Re: Wrong answer. Help pls!! C++ ahahah I'm stupid :D Thanks) Re: Wrong answer. Help pls!! C++ Posted by Agyn 9 Mar 2022 01:34 the task could be solved by shorter way // 2022-03-08.cpp : This file contains the 'main' function. Program execution begins and ends there. // #include <iostream> using namespace std; int main() { int n, k; cin >> n >> k; int droid = 0, bum = 0; int tempBum; for (int i = 0; i < n; i++) { cin >> tempBum; if (tempBum > k) { bum += tempBum - k; } if (k > tempBum) { droid += k - tempBum; } } cout << bum << " " << droid; } |
|
|