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 1079. Maximum

Ilya Why I get WA1(the result of my code is 3 4) [1] // Problem 1079. Maximum 10 Jan 2021 03:54
#include <bits/stdc++.h>

using namespace std;

int main(){
    int n;
    int a[100000];
    a[0] = 0;
    a[1] = 1;
    int max = 1;
    while(cin >> n, n != 0){
        if(n > max){
            for(int i = max + 1; i <= n; ++i){
                if(i % 2 == 0){
                    a[i] = a[i / 2];
                }
                else{
                    a[i] = a[(i - 1) / 2] + a[(i - 1) / 2 + 1];
                }
                max = n;
            }
        }
        cout << a[n - (n % 2 == 0)] << "\n";
    }
}

Edited by author 10.01.2021 03:55
print the maximum value in the range 1 to n
a13 is greater than a15