Codeforces 793A Oleg and shares 题解
来源:互联网 发布:橘子vr软件下载 编辑:程序博客网 时间:2024/06/06 18:29
题意
有n个数,每次操作只可以将其中一个数减k,问最少需要多少次操作才能让所有数相等,若不可能,输出-1
思路
先找到最小的,然后把所有数减到和最小的相等,如果它们的差不能被k整除就不可能成功,否则答案就要加两数之差除以k,最后算下来就是答案
代码
#include <cstdio>long long a[100001];int main(){ long long n,k,minn,f,ans; scanf("%I64d%I64d",&n,&k); minn=1000000001; for(long long i=0;i<n;i++) { scanf("%I64d",&a[i]); if(a[i]<minn) minn=a[i]; } ans=0; f=0; for(long long i=0;i<n;i++) if((a[i]-minn)%k!=0) { f=1; break; } else ans+=(a[i]-minn)/k; if(f) printf("-1\n"); else printf("%I64d\n",ans); return 0;}
0 0
- Codeforces 793A Oleg and shares 题解
- codeforces 793A Oleg and shares
- 【Codeforces 793 A. Oleg and shares】
- Oleg and shares CodeForces
- Oleg and shares (Codeforces
- Oleg and shares CodeForces
- A. Oleg and shares
- CF-Tinkoff Challenge-Elimination Round-A-Oleg and shares
- Codeforces Round #380A - Interview with Oleg
- CodeForces 738A - Interview with Oleg(水题)
- codeforces 738A Interview with Oleg
- codeforces A. Valera and Plates 题解
- codeforces A. Shaass and Oskols 题解
- Codeforces A. Valera and X 题解
- Codeforces #839A: Arya and Bran 题解
- 【57.97%】【codeforces Round #380A】Interview with Oleg
- codeforces - 738A - Interview with Oleg(字符串处理)
- Codeforces 729A Interview with Oleg 简单暴力
- FL2440—独立ADC驱动模块
- MySQL优化
- Linux Java程序debug总结
- iOS之UICololor的使用
- 从DllMain下断点到LdrpCallInitRoutine
- Codeforces 793A Oleg and shares 题解
- Android深入四大组件(三)Service的绑定过程
- Matlab图像处理(02)-图像基础
- 网络互联基础知识
- BZOJ 1407: [Noi2002]Savage 扩展欧几里得
- 【ZJOI2013】bzoj3112 防守战线
- BZOJ 2749: [HAOI2012]外星人
- C语言指针的概念
- HDU 5869 Different GCD Subarray Query(离线处理+树状数组)