2 条题解
-
4
#include<bits/stdc++.h> using namespace std; int n,m,k,s,t,tot,now,ans,M,S,C,a[2001],b[2000]; int main() { cin>>M>>S>>C; if(M>=C) { cout<<C; return 0; } for(int i=1;i<=C;i+=1)cin>>a[i]; sort(a+1,a+C+1); ans=a[C]-a[1]+1; for(int i=1;i<C;i+=1)b[i]=a[i+1]-a[i]-1; sort(b+1,b+C); for(int i=1;i<=M-1;i+=1)ans-=b[C-i]; cout<<ans<<endl; }
-
-3
:
#include <bits/stdc++.h> using namespace std; long long m, s, c, a[205], b[205], ans; int main() { freopen("修理牛棚.in", "r", stdin); freopen("修理牛棚.out", "w", stdout); ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> m >> s >> c; for (int i = 1; i <= c; i++) cin >> a[i]; sort(a + 1, a + c + 1); ans = a[c] - a[1] + 1; for (int i = 1; i <= c - 1; i++) b[i] = a[i + 1] - a[i] - 1; sort(b + 1, b + c); for (int i = c - 1; i >= c - m + 1; i--) ans -= b[i]; cout << ans << endl; return 0; }
- 1
信息
- ID
- 560
- 时间
- 1000ms
- 内存
- 125MiB
- 难度
- 6
- 标签
- 递交数
- 352
- 已通过
- 97
- 上传者