Cod sursa(job #1997082)

Utilizator laurageorgescuLaura Georgescu laurageorgescu Data 3 iulie 2017 12:41:36
Problema Plus Scor 100
Compilator cpp Status done
Runda Simulare 18b Marime 1.12 kb
#include <fstream>

using namespace std;

ifstream fin ("plus.in"); ofstream fout ("plus.out");

typedef long long i64;

const int nmax = 3;
int v[nmax + 1];
i64 a[nmax + 1];

i64 solve (int s) {
    if (v[ 2 ] == 0 && v[ 3 ] == 0) {
        if (s == 0)
            return (a[ 2 ] + 1) * (a[ 3 ] + 1);
        else
            return 0;
    } else if (v[ 2 ] == 0) {
        if (s / v[ 3 ] >= 0 && s / v[ 3 ] <= a[ 3 ])
            return a[ 2 ] + 1;
        else
            return 0;
    } else if (v[ 3 ] == 0) {
        if (s / v[ 2 ] >= 0 && s / v[ 2 ] <= a[ 2 ])
            return a[ 3 ] + 1;
        else
            return 0;
    } else {
        i64 x, y;
        x = (s - a[ 3 ] * v[ 3 ]) / v[ 2 ];
        y = s / v[ 2 ];

        if (x > y)
            swap(x, y);

        return max(1LL * 0, min(y, a[ 2 ]) - max(x, 1LL * 0) + 1);
    }
}

int main() {
    int s;
    fin >> s;
    for (int i = 1; i <= 3; ++ i)
        fin >> a[ i ] >> v[ i ];

    i64 ans = 0;
    for (int i = 0; i <= a[ 1 ]; ++ i) {
        ans += solve(s - i * v[ 1 ]);
    }

    fout << ans << "\n";

    fin.close();
    fout.close();
    return 0;
}