/ Randle /

记录详情

Wrong Answer

/in/foo.cc: In function 'int main()':
/in/foo.cc:36:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if(les.size()>k) {
       ~~~~~~~~~~^~
/in/foo.cc:37:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     while(les.size()>k) {
           ~~~~~~~~~~^~
# 状态 耗时 内存占用
#1 Wrong Answer 2ms 336.0 KiB
#2 Wrong Answer 1ms 324.0 KiB
#3 Wrong Answer 1ms 328.0 KiB
#4 Wrong Answer 2ms 332.0 KiB
#5 Wrong Answer 1ms 328.0 KiB
#6 Wrong Answer 1ms 320.0 KiB
#7 Wrong Answer 1ms 340.0 KiB
#8 Wrong Answer 1ms 328.0 KiB
#9 Wrong Answer 1ms 328.0 KiB
#10 Wrong Answer 2ms 336.0 KiB

代码

#include <stdio.h>
#include <iostream>
#include <queue>
#define maxn 100005
using namespace std;
int a[maxn],b[maxn],suma[maxn],sumb[maxn];
priority_queue<double,vector<double>,greater<double> > gr;
priority_queue<double,vector<double>,less<double> > les;
int main() {
	freopen("test.txt","r",stdin);
	int n,k;
	cin>>n>>k;
	for(int i = 1; i<=n; i++) {
		scanf("%d",a+i);
		suma[i] = suma[i-1]+a[i];
	}
	for(int i = 1; i<=n; i++) {
		scanf("%d",b+i);
		sumb[i] = sumb[i-1]+b[i];
	}
	if(k==1) {
		double maxx  = -1;
		for(int i = 1;i<=n;i++){
			for(int j = 0; j<i; j++) {
			  double toadd = 1.0*(suma[i]-suma[j])/(sumb[i]-sumb[j]);
			  maxx = max(maxx,toadd);
			}
		}
		printf("%.2lf",maxx);
		return 0;
	}
	for(int i = 1; i<=n; i++) {
		for(int j = 0; j<i; j++) {
			double toadd = -1.0*(suma[i]-suma[j])/(sumb[i]-sumb[j]);
			les.push(toadd);
			if(les.size()>k) {
				while(les.size()>k) {
					double t= les.top();
					les.pop();
					gr.push(t);
				}
			}
			if(!gr.empty()) {
				while(gr.top()<les.top()) {
					double t = gr.top();
					gr.pop();
					gr.push(les.top());
					les.pop();
					les.push(t);
				}
			}
		}
	}
	printf("%.2lf",-les.top());
	return 0;
}

信息

递交者
类型
递交
题目
梁山伯与祝英台(原创)
题目数据
下载
语言
C++
递交时间
2017-10-25 19:26:00
评测时间
2017-10-25 19:26:00
评测机
分数
0
总耗时
19ms
峰值内存
340.0 KiB