Saratov State University :: Online Contester


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

::Poll
Are you registered on Codeforces?
Yes
No
What is it???

[results]

::webboard

please help (183 - Painting Balls)
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;
}



see sub-tree reply to that message


::Login
Forgot password?

::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

Server time: 2017-11-23 06:25:45Online Contester Team © 2002 - 2016. All rights reserved.