Add new attachment

Only authorized users are allowed to upload new attachments.

This page (revision-2) was last changed on 28-Feb-2016 19:19 by filipdimitrovski

This page was created on 28-Feb-2016 19:19 by Bojan Kostadinov

Only authorized users are allowed to rename pages.

Only authorized users are allowed to delete pages.

Difference between version and

At line 32 removed one line
#include <vector>
At line 35 changed 14 lines
int main()
{
int n, k;
cin >> n >> k;
vector<int> t;
for (int i=0; i<n; i++)
{
int ti;
cin >> ti;
t.push_back(ti);
const int MAX_N = 100;
const int INT_MAX = 2147483647;
int findMax(int A[], int n, int k) {
int M[MAX_N+1][MAX_N+1] = {0};
int cum[MAX_N+1] = {0};
for (int i = 1; i <= n; i++)
cum[i] = cum[i-1] + A[i-1];
for (int i = 1; i <= n; i++)
M[i][1] = cum[i];
for (int i = 1; i <= k; i++)
M[1][i] = A[0];
for (int i = 2; i <= k; i++) {
for (int j = 2; j <= n; j++) {
int best = INT_MAX;
for (int p = 1; p <= j; p++) {
best = min(best, max(M[p][i-1], cum[j]-cum[p]));
}
M[j][i] = best;
At line 50 changed 8 lines
sort(t.begin(), t.end());
int pos = n - k - 1;
int res = t[pos+1] - t[pos];
cout << res << endl;
return 0;
}
return M[n][k];
At line 59 changed one line
int main(){
int partitions, contests;
cin >> partitions >> contests;
int A[MAX_N];
for(int i = 0; i < contests; i++){
cin >> A[i];
}
cout << findMax(A, contests, partitions) << endl;
}
Version Date Modified Size Author Changes ... Change note
2 28-Feb-2016 19:19 10.463 kB filipdimitrovski to previous алгоритмот беше неточен, ги погодува тестовите по случајност (решението е DP)
1 28-Feb-2016 19:19 10.022 kB Bojan Kostadinov to last
« This page (revision-2) was last changed on 28-Feb-2016 19:19 by filipdimitrovski