Submission #55172

# Submission time Handle Problem Language Result Execution time Memory
55172 2018-07-06T08:16:44 Z Costin Andrei Oncescu(#1304) None (JOI14_ho_t2) C++11
100 / 100
29 ms 748 KB
#include<bits/stdc++.h>

using namespace std;

int N, M, a[10009], dp[20009];
const int INF = 5e8;

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d %d", &N, &M);
for (int i=1; i<=N; i++)
    scanf ("%d", &a[i]);
sort (a + 1, a + N + 1);
reverse (a + 1, a + N + 1);
for (int i=1; i<=2 * N; i++)
    dp[i] = INF;
for (int i=1; i<=M; i++)
{
    int capacity, cost;
    scanf ("%d %d", &capacity, &cost);
    capacity = min (capacity, N);
    for (int j=2 * N; j>=capacity; j--)
        if (dp[j] > dp[j - capacity] + cost)
            dp[j] = dp[j - capacity] + cost;
    for (int j=2 * N; j>=1; j--)
        if (dp[j] < dp[j - 1])
            dp[j - 1] = dp[j];
}
int ans = 0, currS = 0;
for (int i=1; i<=N; i++)
{
    currS += a[i];
    if (currS - dp[i] > ans)
        ans = currS - dp[i];
}
printf ("%d\n", ans);
return 0;
}

Compilation message

2014_ho_t2.cpp: In function 'int main()':
2014_ho_t2.cpp:13:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 scanf ("%d %d", &N, &M);
 ~~~~~~^~~~~~~~~~~~~~~~~
2014_ho_t2.cpp:15:11: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf ("%d", &a[i]);
     ~~~~~~^~~~~~~~~~~~~
2014_ho_t2.cpp:23:11: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf ("%d %d", &capacity, &cost);
     ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 4 ms 616 KB Output is correct
4 Correct 3 ms 616 KB Output is correct
5 Correct 6 ms 616 KB Output is correct
6 Correct 2 ms 616 KB Output is correct
7 Correct 2 ms 616 KB Output is correct
8 Correct 3 ms 616 KB Output is correct
9 Correct 6 ms 616 KB Output is correct
10 Correct 7 ms 616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 660 KB Output is correct
2 Correct 27 ms 660 KB Output is correct
3 Correct 24 ms 660 KB Output is correct
4 Correct 22 ms 660 KB Output is correct
5 Correct 25 ms 720 KB Output is correct
6 Correct 5 ms 720 KB Output is correct
7 Correct 26 ms 720 KB Output is correct
8 Correct 24 ms 720 KB Output is correct
9 Correct 6 ms 720 KB Output is correct
10 Correct 23 ms 748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 4 ms 616 KB Output is correct
4 Correct 3 ms 616 KB Output is correct
5 Correct 6 ms 616 KB Output is correct
6 Correct 2 ms 616 KB Output is correct
7 Correct 2 ms 616 KB Output is correct
8 Correct 3 ms 616 KB Output is correct
9 Correct 6 ms 616 KB Output is correct
10 Correct 7 ms 616 KB Output is correct
11 Correct 23 ms 660 KB Output is correct
12 Correct 27 ms 660 KB Output is correct
13 Correct 24 ms 660 KB Output is correct
14 Correct 22 ms 660 KB Output is correct
15 Correct 25 ms 720 KB Output is correct
16 Correct 5 ms 720 KB Output is correct
17 Correct 26 ms 720 KB Output is correct
18 Correct 24 ms 720 KB Output is correct
19 Correct 6 ms 720 KB Output is correct
20 Correct 23 ms 748 KB Output is correct
21 Correct 19 ms 748 KB Output is correct
22 Correct 21 ms 748 KB Output is correct
23 Correct 29 ms 748 KB Output is correct
24 Correct 22 ms 748 KB Output is correct
25 Correct 21 ms 748 KB Output is correct
26 Correct 21 ms 748 KB Output is correct
27 Correct 8 ms 748 KB Output is correct
28 Correct 25 ms 748 KB Output is correct
29 Correct 28 ms 748 KB Output is correct
30 Correct 26 ms 748 KB Output is correct