> 文档中心 > NOIP 2010 普及组 接水问题

NOIP 2010 普及组 接水问题

#include using namespace std;int n, m, x;int a[105];int main() {cin >> n >> m;for (int i = 1; i <= n; i ++ ) {cin >> x;int t = 1;for (int j = 2; j <= m; j ++ ) {if (a[j] < a[t]) t = j;}a[t] += x;}int maxx = 0;for (int j = 1; j <= m; j ++ ) {maxx = max(maxx, a[j]);}cout << maxx;return 0;}
#include using namespace std;int n, m, x;priority_queue <int, vector<int>, greater<int> > q;int main() {cin >> n >> m;for (int i = 1; i <= m; i ++) q.push(0);for (int i = 1; i <= n; i ++ ) {cin >> x;intt = q.top();q.pop();q.push(t + x);}for (int j = 1; j < m; j ++ ) q.pop();cout << q.top();return 0;}

歌词网