use strict; use warnings; use feature qw/say/; # https://yukicoder.me/problems/5 # my $input = "1000 # 1000 # 1000 # "; my $input = <>; chomp $input; my $hash_ref; ( $hash_ref->{100}, $hash_ref->{25}, $hash_ref->{1} ) = split /\n/, $input; chomp( $hash_ref->{100}, $hash_ref->{25}, $hash_ref->{1} ); if ( $hash_ref->{1} >= 25 ) { my $move_up = int( $hash_ref->{1} / 25 ); $hash_ref->{25} += $move_up; $hash_ref->{1} -= $move_up * 25; } if ( $hash_ref->{25} >= 4 ) { my $move_up = int( $hash_ref->{25} / 4 ); $hash_ref->{100} += $move_up; $hash_ref->{25} -= $move_up * 4; } if ( $hash_ref->{100} >= 10 ) { my $move_up = int( $hash_ref->{100} / 10 ); $hash_ref->{100} = $hash_ref->{100} - $move_up * 10; } # say $hash_ref->{1}; # say $hash_ref->{25}; # say $hash_ref->{100}; my $sum = 0; for my $n ( 1, 25, 100 ) { $sum += $hash_ref->{$n}; } say $sum;