Submission #994134

# Submission time Handle Problem Language Result Execution time Memory
994134 2024-06-07T07:09:02 Z vjudge1 Kas (COCI17_kas) C++17
70 / 100
68 ms 1124 KB
#include<bits/stdc++.h>

using namespace std;

const int SM = 1e5+1, inf = 1e9;
int dp[2][SM];

int main()
{
  int n;
  cin >> n;
  int a[1 + n];
  int x = 0;
  for(int i = 1; i <= n;  ++i)
    {
      cin >> a[i];
      x += a[i];
    }

  for(int j = 1; j <= x; j++)
    dp[0][j] = -inf;
  
  for(int i = 1; i <= n; i ++)
    {
      bool b = i & 1, nb = !b;

      for(int j = 0; j <= x; j++)
	{
	  dp[b][j] = dp[nb][j];
	  if(j >= a[i])
	    dp[b][j] = max(dp[b][j], dp[nb][j - a[i]]);

	  if(a[i] + j <= x)
	    dp[b][j] = max(dp[b][j], dp[nb][j + a[i]] + a[i]);
	}
    }

  int mx = max(0, dp[n & 1][0]);
  cout << mx + (x - 2 * mx) << endl;
  return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 1116 KB Output is correct
2 Correct 34 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 1116 KB Output is correct
2 Correct 55 ms 1124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 61 ms 1112 KB Output is correct
2 Correct 68 ms 1116 KB Output is correct