#include <stdio.h> int main() { long long int fieldSize = 0; long long int harvestsAmount = 0; scanf("%d", &fieldSize); scanf("%d", &harvestsAmount); long long int summaryHeight = 0; long long int cropsHeight = 0; for (int i = 0; i < fieldSize; i++) { scanf("%lld", &cropsHeight); summaryHeight += cropsHeight; } long long int harvestDay = 0; long long int desiredHeight = 0; long long int todayIncome = 0; long long int actualCropsHeight = 0; long long int currentDay = 0; for (int i = 1; i <= harvestsAmount; i++) { harvestDay = 0; desiredHeight = 0; todayIncome = 0; scanf("%lld", &harvestDay); scanf("%lld", &desiredHeight); //for (long long int d = currentDay; d < harvestDay; d++) //{ // actualCropsHeight += summaryHeight; //} actualCropsHeight += summaryHeight * (harvestDay - currentDay); currentDay = harvestDay; // actualCropsHeight += (summaryHeight*(harvestDay-i)); todayIncome = actualCropsHeight - fieldSize*desiredHeight; if (todayIncome > 0) { actualCropsHeight -= todayIncome; printf("%lld\n", todayIncome); } else { printf("0\n"); } } return 0; }
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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | #include <stdio.h> int main() { long long int fieldSize = 0; long long int harvestsAmount = 0; scanf("%d", &fieldSize); scanf("%d", &harvestsAmount); long long int summaryHeight = 0; long long int cropsHeight = 0; for (int i = 0; i < fieldSize; i++) { scanf("%lld", &cropsHeight); summaryHeight += cropsHeight; } long long int harvestDay = 0; long long int desiredHeight = 0; long long int todayIncome = 0; long long int actualCropsHeight = 0; long long int currentDay = 0; for (int i = 1; i <= harvestsAmount; i++) { harvestDay = 0; desiredHeight = 0; todayIncome = 0; scanf("%lld", &harvestDay); scanf("%lld", &desiredHeight); //for (long long int d = currentDay; d < harvestDay; d++) //{ // actualCropsHeight += summaryHeight; //} actualCropsHeight += summaryHeight * (harvestDay - currentDay); currentDay = harvestDay; // actualCropsHeight += (summaryHeight*(harvestDay-i)); todayIncome = actualCropsHeight - fieldSize*desiredHeight; if (todayIncome > 0) { actualCropsHeight -= todayIncome; printf("%lld\n", todayIncome); } else { printf("0\n"); } } return 0; } |