### Saratov State University :: Online Contester

::Go
- home
- news
- register
 - update personal info
 - problemset archive
- submit
- status online
- standing
- contests
- virtual contests
- forum
- statistic
- FAQ
- projects

 ::Poll Are you registered on Codeforces?YesNoWhat is it???[results]

::webboard

Author: Mirzakhmet Syzdykov
ID: 004300
Problem: 183
Contest: 0
Date: 2011-08-14 21:36:35

What's wrong with my algorithm please tell me if you solved it:

#include <stdio.h>

int main()
{
int n, m;
scanf ("%d %d", &n, &m);
int *c = new int[n], *d = new int[n + 1], *e = new int [n + 1];
int i, j, k;
for (i = 0; i < n; ++i) scanf ("%d", c + i);
for (i = 0; i < n; ++i) d[i] = 0;
for (i = 0; i < n; ++i) {
if (d[i] == 0) d[i] = c[i];
for (j = i + 1, k = 0; j < n && k < (m - 1); ++j, ++k)
if ((d[i] + c[j]) < d[j] || d[j] == 0) d[j] = d[i] + c[j];
}
for (i = 0; i < n; ++i) e[i] = 0;
for (i = n - m; i < n; ++i) {
for (j = i + 1; j < n; ++j) {
if ((d[i] + c[j]) < e[j] || e[j] == 0) e[j] = d[i] + c[j];
}
}
int result = 0;
for (i = n - m; i < n; ++i) {
for (j = i + 1; j < n; ++j)
if ((d[i] + c[j]) < result || result == 0) result = d[i] + c[j];
}

printf ("%dn", result);
return 0;
}

 ::News 22.10.12 - The problems from the Southern Subregional Programming Contest 2012 added to the problemset archive (542 - 553). 22.10.12 - After the start of the contest the statements in PDF will be available by the link.23.10.11 - The problems from the Southern Subregional Programming Contest 2011 added to the problemset archive (530 - 541).

::Counter