/* * siano.cpp * * Created on: 29 wrz 2015 * Author: segfault */ #include <cstdio> #include <algorithm> int main() { int species_count, cut_count; scanf("%d%d", &species_count, &cut_count); int* growth_speed = new int[species_count]; for (int i = 0; i < species_count; i++) { scanf("%d", &growth_speed[i]); } int* height = new int[species_count]; for (int i = 0; i < species_count; i++) { height[i] = 0; } int day, cut_h, pre_cut_h, last_cut = 0, out; for (int i = 0; i < cut_count; i++) { out = 0; scanf("%d%d", &day, &cut_h); for (int i = 0; i < species_count; i++) { pre_cut_h = height[i] + growth_speed[i] * (day - last_cut); out += std::max(pre_cut_h - cut_h, 0); height[i] = std::min(pre_cut_h, cut_h); } last_cut = day; printf("%d\n", out); } }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | /* * siano.cpp * * Created on: 29 wrz 2015 * Author: segfault */ #include <cstdio> #include <algorithm> int main() { int species_count, cut_count; scanf("%d%d", &species_count, &cut_count); int* growth_speed = new int[species_count]; for (int i = 0; i < species_count; i++) { scanf("%d", &growth_speed[i]); } int* height = new int[species_count]; for (int i = 0; i < species_count; i++) { height[i] = 0; } int day, cut_h, pre_cut_h, last_cut = 0, out; for (int i = 0; i < cut_count; i++) { out = 0; scanf("%d%d", &day, &cut_h); for (int i = 0; i < species_count; i++) { pre_cut_h = height[i] + growth_speed[i] * (day - last_cut); out += std::max(pre_cut_h - cut_h, 0); height[i] = std::min(pre_cut_h, cut_h); } last_cut = day; printf("%d\n", out); } } |