#include <stdio.h>
int calcTotalTax(int n, long amounts[]) {
int totalTax = 0;
for (int i = 0; i < n; i++) {
if (amounts[i] > 1000) {
// Calculate the taxable amount
long taxableAmount = amounts[i] - 1000;
// Calculate the tax (10% of the taxable amount)
totalTax += taxableAmount / 10; // Integer division to ignore fractions
}
}
return totalTax;
}
int main() {
// Example test case
long amounts[] = {1000, 2000, 3000, 4000, 5000};
int n = 5;
int totalTax = calcTotalTax(n, amounts);
printf("%d\n", totalTax
); // Output: 1000
// Additional test cases
long test1[] = {1000}; // Expected output: 0
long test2[] = {2000}; // Expected output: 100
long test3[] = {3000, 4000, 5000}; // Expected output: 900
long test4[] = {1500, 2500, 3500, 4500}; // Expected output: 800
long test5[] = {0, 500, 1000}; // Expected output: 0
printf("%d\n", calcTotalTax
(1, test1
)); // Output: 0 printf("%d\n", calcTotalTax
(1, test2
)); // Output: 100 printf("%d\n", calcTotalTax
(3, test3
)); // Output: 900 printf("%d\n", calcTotalTax
(4, test4
)); // Output: 800 printf("%d\n", calcTotalTax
(3, test5
)); // Output: 0
return 0;
}
CiNpbmNsdWRlIDxzdGRpby5oPgoKaW50IGNhbGNUb3RhbFRheChpbnQgbiwgbG9uZyBhbW91bnRzW10pIHsKICAgIGludCB0b3RhbFRheCA9IDA7CgogICAgZm9yIChpbnQgaSA9IDA7IGkgPCBuOyBpKyspIHsKICAgICAgICBpZiAoYW1vdW50c1tpXSA+IDEwMDApIHsKICAgICAgICAgICAgLy8gQ2FsY3VsYXRlIHRoZSB0YXhhYmxlIGFtb3VudAogICAgICAgICAgICBsb25nIHRheGFibGVBbW91bnQgPSBhbW91bnRzW2ldIC0gMTAwMDsKICAgICAgICAgICAgLy8gQ2FsY3VsYXRlIHRoZSB0YXggKDEwJSBvZiB0aGUgdGF4YWJsZSBhbW91bnQpCiAgICAgICAgICAgIHRvdGFsVGF4ICs9IHRheGFibGVBbW91bnQgLyAxMDsgLy8gSW50ZWdlciBkaXZpc2lvbiB0byBpZ25vcmUgZnJhY3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