酷代码 AI
菜单
服务商

明朝朱权时期:张居正与冯保助力,C 语言求解大臣权力调整最小代价难题

```c #include <stdio.h> #include <stdlib.h> #define MOD 18446744073709551616 int cmp(const void *a, const void *b) { return *(int*)a - *(int*)b; } unsigned long long minCost(int n, int *num, int *cost) { qsort(cost, n, sizeof(int), cmp); unsigned long long totalCost = 0; for (int i = 0; i < n; i++) { totalCost += (unsigned long long)num[i] * cost[i] % MOD; } return totalCost % MOD; } int main() { int n; scanf("%d", &n); int *num = (int*)malloc(n * sizeof(int)); int *cost = (int*)malloc(n * sizeof(int)); for (int i = 0; i < n; i++) { scanf("%d", &num[i]); } for (int i = 0; i < n; i++) { scanf("%d", &cost[i]); } unsigned long long result = minCost(n, num, cost); printf("%llu\n", result); free(num); free(cost); return 0; } ``` ######[AI写代码神器 | 570点数解答 | 2024-11-10 19:21:52]

相关提问
本站限时免费提问中
实用工具查看更多
Linux在线手册 [开发类]
Jquery在线手册 [开发类]
今日油价 [生活类]
图片互转base64 [开发类]
时间转换器 [开发类]