有两种理解方法。虽然对于相同的数据有不同的输出,但据说都能过。但是我的其中一个没过。
View Code
#include < iostream > #include < cstdio > #include < cstdlib > #include < cstring > #include < algorithm > using namespace std; #define maxn 30005 int n, m; int f[maxn], sum[maxn]; int main(){ // freopen("t.txt", "r", stdin); scanf( " %d%d " , & n, & m); for ( int i = 1 ; i <= n; i ++ ) scanf( " %d " , & f[i]); for ( int i = 1 ; i <= n; i ++ ) f[i] = f[i] % m; int ans = 0 ; for ( int i = 1 ; i <= n; i ++ ) if (f[i] != 0 ) ans = max(ans, m - f[i]); printf( " %d\n " , ans); return 0 ;}