Submission #994133

# Submission time Handle Problem Language Result Execution time Memory
994133 2024-06-07T07:06:41 Z vjudge1 Kas (COCI17_kas) C++17
70 / 100
67 ms 1224 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]);
	  // cerr << "dp[" << i << "][" << j << "] = " << dp[b][j] << endl;
	}
    }

  int mx = 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 504 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 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 1 ms 348 KB Output is correct
2 Correct 0 ms 436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 440 KB Output is correct
2 Correct 1 ms 400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 1224 KB Output is correct
2 Correct 34 ms 1220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 1116 KB Output is correct
2 Correct 55 ms 1112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 60 ms 1112 KB Output is correct
2 Correct 67 ms 1116 KB Output is correct