Submission #55171

# Submission time Handle Problem Language Result Execution time Memory
55171 2018-07-06T08:15:25 Z Costin Andrei Oncescu(#1304) None (JOI14_ho_t2) C++11
0 / 100
4 ms 520 KB
#include<bits/stdc++.h>

using namespace std;

int N, M, a[509], dp[1009];
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 2 ms 248 KB Output is correct
2 Correct 3 ms 356 KB Output is correct
3 Execution timed out 3 ms 520 KB Time limit exceeded (wall clock)
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 520 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 3 ms 356 KB Output is correct
3 Execution timed out 3 ms 520 KB Time limit exceeded (wall clock)
4 Halted 0 ms 0 KB -