Submission #1695242


Source Code Expand

#include <stdio.h>
#include <stdlib.h>

#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define STR(i,str) for(int i=0;(str)[i];i++)
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX3(a,b,c) ((a)>(b)?(a)>(c)?(a):(c):(b)>(c)?(b):(c))
#define MIN3(a,b,c) ((a)<(b)?(a)<(c)?(a):(c):(b)<(c)?(b):(c))
#define RNG(a,b) ((a)>(b)?(a)-(b):(b)-(a))
#define RNG3(a,b,c) ((a)>(b)?(b)>(c)?(a)-(c):(c)>(a)?(c)-(b):(a)-(b):(b)>(c)?(c)>(a)?(b)-(a):(b)-(c):(c)-(a))
#define MAXS(a,b) {if((a)<(b))(a)=(b);}
#define MINS(a,b) {if((a)>(b))(a)=(b);}

#define INF 2147483647

int main(){
	int n, k, *a, ans = 0;
	scanf("%d%d", &n, &k);
	a = (int *)malloc(sizeof(int) * n);
	for(int i = 0; i < n; i++){
		scanf("%d", a + i);
		int k = i, tmp = a[i];
		while(tmp > a[(k-1)/2]) a[k] = a[(k-1)/2], a[k = (k-1)/2] = tmp;
	}
	for(int i = n - 1; i >= n - k; i--){
		ans += a[0];
		int k = 0, tmp = a[0] = a[i];
		a[i] = -INF;
		for(;;)
			if(k < i/2)
				if(tmp < a[k*2 + 1])
					if(a[k*2 + 1] > a[k*2 + 2])
						a[k] = a[k*2 + 1], a[k = k*2 + 1] = tmp;
					else goto Label;
				else if(tmp < a[k*2 + 2]) Label:
					a[k] = a[k*2 + 2], a[k = k*2 + 2] = tmp;
				else break;
			else break;
	}
	printf("%d\n", ans);
}

Submission Info

Submission Time
Task B - Snake Toy
User toga57
Language C++14 (GCC 5.4.1)
Score 200
Code Size 1392 Byte
Status AC
Exec Time 1 ms
Memory 128 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:22:23: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &k);
                       ^
./Main.cpp:25:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", a + i);
                     ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 200 / 200
Status
AC × 2
AC × 10
Set Name Test Cases
Sample 00_example_01.txt, 00_example_02.txt
All 00_example_01.txt, 00_example_02.txt, 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt
Case Name Status Exec Time Memory
00_example_01.txt AC 1 ms 128 KB
00_example_02.txt AC 1 ms 128 KB
01.txt AC 1 ms 128 KB
02.txt AC 1 ms 128 KB
03.txt AC 1 ms 128 KB
04.txt AC 1 ms 128 KB
05.txt AC 1 ms 128 KB
06.txt AC 1 ms 128 KB
07.txt AC 1 ms 128 KB
08.txt AC 1 ms 128 KB