시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
3 초 128 MB 325 85 62 26.957%

문제

상근이는 N행 3열로 이루어진 체스판을 가지고 있다. 

상근이가 잠시 외출한 사이 창영이는 체스판의 모든 칸에 정수를 썼고, 바닥에 도미노 K개를 놓고 도망갔다.

외출에서 돌아온 상근이는 애지중지 하는 체스판에 정수가 쓰여 있는 것을 보고 큰 충격에 빠졌다.

창영이는 상근이가 슬퍼하는 모습을 견딜 수가 없었다. 창영이는 도미노를 모두 사용해 체스판을 덮으려고 한다. 도미노의 크기는 2×1이고, 도미노를 모두 사용해 체스판을 덮어야 한다. 도미노는 서로 겹칠 수 없고, 회전 시킬 수 있다. 도미노는 항상 체스판의 두 칸을 차지해야 한다.

도미노를 이용해 체스판을 덮는 방법은 여러 가지가 있다. 이때, 도미노로 덮은 칸에 쓰여 있는 수의 합의 최댓값을 구하는 프로그램을 작성하시오.

입력

첫째 줄에 N과 K가 주어진다. (1 ≤ N ≤ 1000, 1 ≤ K ≤ 1000)

다음 N개 줄에는 체스판의 i번째 행에 쓰여 있는 수 세 개가 주어진다. 모든 수는 절댓값이 106보다 작은 정수이다.

출력

첫째 줄에 도미노 K개를 이용해 덮은 칸에 쓰여 있는 수를 모두 더했을 때, 합의 최댓값을 구하는 프로그램을 작성하시오.

예제 입력 1

5 3
2 1 -1
1 3 2
0 2 3
2 1 1
3 3 0

예제 출력 1

16
W3sicHJvYmxlbV9pZCI6Ijk5MzYiLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJcdWNjYjRcdWMyYTRcdWI4NWMgXHViM2M0XHViYmY4XHViMTc4XHViOTdjIFx1ZDBjMFx1Yzc5MCIsImRlc2NyaXB0aW9uIjoiPHA+XHVjMGMxXHVhZGZjXHVjNzc0XHViMjk0IE5cdWQ1ODkgM1x1YzVmNFx1Yjg1YyBcdWM3NzRcdWI4ZThcdWM1YjRcdWM5YzQgXHVjY2I0XHVjMmE0XHVkMzEwXHVjNzQ0IFx1YWMwM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250YWlucyB0aGUgaW50ZWdlciBOICgxICZsZTsgTiAmbGU7IDEwMDApLCB0aGUgbnVtYmVyIG9mIHJvd3MsIGFuZCBLICgxICZsZTsgSyAmbGU7IDEwMDApLCB0aGUgbnVtYmVyIG9mIGRvbWlub2VzIGF2YWlsYWJsZS4mbmJzcDs8XC9wPlxyXG5cclxuPHA+RWFjaCBvZiB0aGUgZm9sbG93aW5nIE4gbGluZXMgY29udGFpbnMgdGhyZWUgaW50ZWdlcnMgd3JpdHRlbiBpbiB0aGUgaTxzdXA+dGg8XC9zdXA+IHJvdyBvZiB0aGUgYm9hcmQuIEFsbCBudW1iZXJzIHdpbGwgYmUgbGVzc2VyIHRoYW4gMTA2IGJ5IGFic29sdXRlIHZhbHVlLiZuYnNwOzxcL3A+XHJcbiIsIm91dHB1dCI6IjxwPlRoZSBmaXJzdCBhbmQgb25seSBsaW5lIG9mIG91dHB1dCBtdXN0IGNvbnRhaW4gdGhlIG1heGltYWwgc3VtIHBvc3NpYmxlIHRvIGNvdmVyIHdpdGggZXhhY3RseSBLIGRvbWlub2VzLiZuYnNwOzxcL3A+XHJcbiIsImhpbnQiOiI8cD5JdCBpcyBvcHRpbWFsIHRvIHBsYWNlIGFsbCBkb21pbm9lcyBob3Jpem9udGFsbHkgYW5kIGFsb25nIHRoZSByaWdodCBlZGdlIG9mIHRoZSBzZWNvbmQgcm93LCByaWdodCBlZGdlIG9mIHRoZSB0aGlyZCByb3cgYW5kIGFsb25nIHRoZSBsZWZ0IGVkZ2Ugb2YgdGhlIGZpbmFsIHJvdy4mbmJzcDs8XC9wPlxyXG4iLCJvcmlnaW5hbCI6IjEiLCJwcm9ibGVtX2xhbmdfY29kZSI6Ilx1YzYwMVx1YzViNCJ9XQ==

출처

Contest > Croatian Open Competition in Informatics > COCI 2013/2014 > Contest #5 4번

  • 문제를 번역한 사람: baekjoon
  • 문제의 오타를 찾은 사람: jh05013