newbie question (time frame) 4hrs

Pages: 12
They designed a sticker set consisting of [n] stickers and provided a level of happiness for each sticker. the [i] sticker sends [ai] happiness and Adds to the happiness of the other side.

Each user is allowed to use a maximum of one [m] sticker in a message and one sticker of 0, 1 or more, but cannot use more than [k] in each successive sticker.

Write a program that specifies the maximum amount of happiness that any user can transfer to the other user by designing a sticker set.


input :

The first line contains [3] integers [n],[ m] and [k]. The second line contains n integer with [ai] amount of happiness .


2 <= n <= 50

2 <= m,k <= 2*10^9



output :

Print the maximum amount of happiness produced by the sticker set .


 

INPUT :

6 9 2
1 3 3 7 4 2

OUTPUT :

54




***UPDATE :

so i wrote this :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <iostream>
using namespace std;
int main()
{

	int n, m, k , p ,t=0,g=0,s=0,u=0;
	cin >> n >> m >> k;

	for (int i = 1; i <= n; i++)
	{
		cin >> p;
		if (p > t)
		{
			g = t;
		}
		if (p >= t)
		{
			t = p;
		}
		if (t > p && g < p|| i == 1)
		{
			g = p;
		}

		
	}

	for (int i = 1; i <= m; i++)
	{
		u++;

		if (u <= k)
		{
			s += t;

		}
		if (u == k)
		{
			s += g;
			i++;
			u = 0;
		}

	}

	cout << s;
}


and i get this :



Compiled Successfully
Test 1
ACCEPTED
Test 2
Time Limit Exceeded
Test 3
ACCEPTED
Test 4
ACCEPTED
Test 5
WRONG ANSWER
Test 6
WRONG ANSWER
Test 7
WRONG ANSWER
Test 8
Time Limit Exceeded
Test 9
Time Limit Exceeded
Test 10
Time Limit Exceeded
Test 11
Time Limit Exceeded
Test 12
WRONG ANSWER
Test 13
Time Limit Exceeded
Test 14
WRONG ANSWER
Test 15
Time Limit Exceeded
Test 16
Time Limit Exceeded
Test 17
Time Limit Exceeded
Test 18
WRONG ANSWER





can someone help ?
Last edited on
@John3682

Nothing in your program corresponds to what you show in 'I get this :'

Show us the actual program you're using for the result you show, or show us the actual result you get with your program you show. Then we can help..
what u see is online test i dont know the numbers it enters or the answer it gets . it just shows which test succeed and which one failed.


the program output is a [ number ] .
anyone ?
hey andy

i can mess around with it till i solve the time limit but what im stuck at is the wrong answers , i need a better code than mine that solve the wrong answers .

ty
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <iostream>
using namespace std;
int main()
{

	int n, m, k, p;
	int t = 0, g = 0, s = 0, u = 0,i=1;
	cin >> n >> m >> k;

	do
	{
		cin >> p;
		i++;
		if (p > t)
		{
			g = t;
		}
		if (p >= t)
		{
			t = p;

		}
		if (t > p && g < p)
		{
			g = p;
		}

	} while (i <= n);


	for (int i = 1; i <= m; i++)
	{
		u++;

		if (u <= k)
		{
			s += t;

		}if (u == k)
		{
			i++;
		}
		if (u == k && i <= m)
		{
			s += g;
			u = 0;
		}

	}

	cout << s;
}


i change it but it didnt make any different in result .
in the example :

6 is the given numbers = 1 3 3 7 4 2

9 is the number of times we can use this numbers like 111111111 or 777777777

but k or 2 says that we cant use a number continuously like 111111111 we could use 7713342213

but i need the max number i could get
so i think the combination of the example is : 774774774 = 54 i think

2<=n<=50

2<=m,k<=2*10^9
Last edited on
guys can someone help me . i could really use ur helps ;
Hard to understand what the problem is or what your code is trying to do :/

Also, what are these problems for?
the last one i was just solving it for fun to see if i can , but this one is is for class and i have like 1 hrs to solve
Last edited on
if u dont understand the problem (i assume its bcz of my sh*** grammar since i used GT) can u fix the time limit for this one too ?

ty in adv
I combined your two loops:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <iostream>

using namespace std;

int main()
{

	int n, m, k, p;
	int t = 0, g = 0, s = 0, u = 0, i = 1;
	cin >> n >> m >> k;

	int bigger = (n > m) ? n : m;

	do
	{

		if (i <= n)
		{
			cin >> p;
			i++;
			if (p > t)
			{
				g = t;
			}
			if (p >= t)
			{
				t = p;

			}
			if (t > p && g < p)
			{
				g = p;
			}
		}


		if (i <= m)
		{
			u++;

			if (u <= k)
			{
				s += t;

			}if (u == k)
			{
				i++;
			}
			if (u == k && i <= m)
			{
				s += g;
				u = 0;
			}
		}

	} while (i <= n);

	cout << s;
}


If the second loop relied on the first loop to finish first, then this won't work (which it seems to). Another way would be this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <iostream>

using namespace std;

int main()
{

	int n, m, k, p;
	int t = 0, g = 0, s = 0, u = 0, i = 1;
	cin >> n >> m >> k;

	do
	{
		cin >> p;
		i++;
		if (p >= t)
		{
			t = p;
			if (p > t)
			{
				g = t;
			}

		}
		else if (t > p && g < p)
		{
			g = p;
		}

	} while (i <= n);


	for (int i = 1; i <= m; i++)
	{
		u++;

		if (u <= k)
		{
			s += t;
			if (u == k)
			{
				i++;
				if (u == k && i <= m)
				{
					s += g;
					u = 0;
				}
			}
		}
	}

	std::cout << s;
}


The second one is tweaked to do less if statements when not needed. But probably won't bring run-time low enough.
Last edited on
hey man

not only they didnt bring down the time limit with these two it gives me 0% for the first one and 16 for the second one but for this :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <iostream>
using namespace std;

int main()
{
	long int n, m, k, p;
	long int t = 0, g = 0, s = 0, u = 0;

	cin >> n >> m >> k;

	for (int i = 1; i <= n; i++)
	{
		cin >> p;

		if (p > t)
		{
			g = t;
		}
		if (p >= t)
		{
			t = p;

		}
		if (t > p && g <= p)
		{
			g = p;
		}

	}

	for (int i = 1; i <= m; i++)
	{
		u++;
		if (u <= k)
		{
			s += t;

		}if (u == k)
		{
			i++;
		}

		if (u == k && i <= m)
		{
			s += g;
			u = 0;
		}

	}

	cout << s;
}


it gives me 44% with one error :


Compiled Successfully
Test 1
ACCEPTED
Test 2
Time Limit Exceeded
Test 3
ACCEPTED
Test 4
ACCEPTED
Test 5
ACCEPTED
Test 6
WRONG ANSWER
Test 7
ACCEPTED
Test 8
Time Limit Exceeded
Test 9
Time Limit Exceeded
Test 10
Time Limit Exceeded
Test 11
Time Limit Exceeded
Test 12
ACCEPTED
Test 13
Time Limit Exceeded
Test 14
ACCEPTED
Test 15
Time Limit Exceeded
Test 16
Time Limit Exceeded
Test 17
Time Limit Exceeded
Test 18
ACCEPTED
if u could somehow solve the time limit i could start working on that error which would be better than being stuck for 3 hrs (i need to send this even the time is running out sure im not getting the whole point but its better than 0)



ps : ty for all ur support
if anyones online , can u take a look ?
Sorry. The last program I could at least tell what it was doing when looking at the code. This program is a bit more vague and I don't know what "rules" I could make use of to lessen operation time.
ok just forget about my code and try to write this : (if u have the time and u dont mind ty in adv)


it gives u 3 number in line one like : 6 9 2 (for example)

6 is the number of numbers its going to enter in line 2 [ like : 1 3 3 7 2 4]

9 is the number ure suppose to write [combination of line 2 numbers]

and 2 tells u that u cant use a number (of the given numbers in line 2) more than limited [k] times right after u used them like u cant write (if the n was 3 and the range was 1 5 9 and the k was 2 the limit ) : 1 1 1 or 333 or 555 u have to either write 1 13 . 3 3 1 . 9 9 1 . 9 9 3 . . . .

and u should aim for the highest number like use : 9 9 3 highest number 9 in this case and the second highest 3



in this thread the highest number is 7 and second highest is 4 so i think the combination would be : 7+7+4 +7 +7 +4 +7 +7 +4 = 54 total length is 9 and i didnt use a number more than k times [2 in this case ] right after i wrote [k] of it
Last edited on
ok so this is the final code works 100% on pc :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>
using namespace std;

int main()
{
	long int n, m, k, p;
	long int t = 0, g = 0, s = 0, u = 0;

	cin >> n >> m >> k;

	for (int i = 1; i <= n; i++)
	{
		cin >> p;
		if (p >= t)
		{
			g = t;
			t = p;
		}
		if (t > p&& g <= p)
		{
			g = p;
		}

	}

	for (long int j = 1; j <= m; j++)
	{
		u++;

		if (u <= k)
		{
			s += t;

		}if (u == k)
		{
			j++;
		}
		if (j > m)
		{
			break;
		}
		if (u == k && j <= m)
		{
			s += g;
			u = 0;
		}

	}

	cout << s;
}

i just need the time limit gone
You don't need a loop for the second part.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>

int main()
{
    std::ios_base::sync_with_stdio( false );

    long n, m, k;
    std::cin >> n >> m >> k;

    long high1 = 0, high2 = 0;
    for( long i = 0; i < n; ++i )
    {
        long x;
        std::cin >> x;
        if     ( x > high1 ) { high2 = high1; high1 = x; }
        else if( x > high2 )   high2 = x;
    }

    ++k;
    std::cout << (m / k * (high1 * (k - 1) + high2))
               + (m % k * high1) << '\n';
}

Last edited on
Pages: 12