Barney goes to Work

Barney is a busy guy. He can only afford to come to his office on 100 days.

Goliath National Bank decided to pay him $ a i \$a_i if he comes on day i i and fine him $ b i \$b_i if he misses day i i .

This being the lists < a i > <a_i> and < b i > <b_i> , for n = 1 0 4 n = 10^4 days, what is the minimum amount that Barney would have to pay Goliath National Bank at the end of the year?

  • Input Format: Line 1 contains all a i a_i sequentially from i = 1 i = 1 to 1 0 4 10^4 and Line 2 contains all the corresponding b i b_i


The answer is 392268547939.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

1 solution

Barney’s earning = p a y w o r k f i n e m i s s \text{Barney's earning} = pay_{work} - fine_{miss} = p a y w o r k + f i n e w o r k f i n e w o r k f i n e m i s s = pay_{work} + fine_{work} - fine_{work} - fine_{miss} = ( p a y + f i n e ) w o r k f i n e w o r k + m i s s = (pay + fine)_{work} - fine_{work + miss}

maximise pay + fine to find the answer.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
#include <cstdio>
#include <algorithm>
using namespace std;
int main()
{
    unsigned long int a[10000], b[10000], c[10000];
    unsigned long int max_sum = 0, sum_b = 0;
    for(int i = 0; i < 10000; i++){
        scanf("%lu", &a[i]);
    }
    for(int i = 0; i < 10000; i++){
        scanf("%lu", &b[i]);
        sum_b += b[i];
        c[i] = a[i] + b[i];
    }
    sort(c, c+10000);
    for(int i = 10000 - 100; i < 10000; i++) max_sum += c[i];
    printf("sum_b = %lu\nmax sum = %lu", sum_b, max_sum);
}

max earning = max_sum - sum_b = 106882249890 - 499150797829 = -392268547939

Poor Barney!

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...