ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1991. The battle near the swamp

TIU_Sarexer Wrong answer. Help pls!! C++ [3] // Problem 1991. The battle near the swamp 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;
}
ToadMonster Re: Wrong answer. Help pls!! C++ [1] // Problem 1991. The battle near the swamp 3 Nov 2016 18:23
> raz = 5 - arr[i];

Why "5" ?
ahahah I'm stupid :D Thanks)
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;
}