ENG  RUS Timus Online Judge
Online Judge
Problems
Authors
Online contests
Site news
Webboard
Problem set
Submit solution
Judge status
Guide
Register
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

## Discussion of Problem 1991. The battle near the swamp

Posted by TIU_Sarexer 3 Nov 2016 16:33
#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++
Posted by ToadMonster 3 Nov 2016 18:23
> raz = 5 - arr[i];

Why "5" ?
Re: Wrong answer. Help pls!! C++
Posted by TIU_Sarexer 3 Nov 2016 20:20
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;
}