Submission #140120

# Submission time Handle Problem Language Result Execution time Memory
140120 2019-08-02T06:14:24 Z StevenH Sails (IOI07_sails) C++14
70 / 100
1000 ms 2568 KB
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <ctime>
using namespace std;
const int maxn=100005;
struct Mast{
	int h,k;
}m[maxn];
bool comp(Mast &x,Mast &y)
{return x.h<y.h;}
int n;
int s[maxn];
int main()
{
	clock_t start;
	start=clock();
	scanf("%d",&n);

	for(int i=0;i<n;i++)
		scanf("%d%d",&m[i].h,&m[i].k);

	int r=0;
	int ed=0;
	sort(m,m+n,comp);
	
	for(int i=0;i<n;i++)
	{
		int res=m[i].h-r;
		r=m[i].h;
		s[0]+=res;
		/*for(int i=0;i<=ed;i++)printf("%d ",s[i]);
		printf("\n");*/
		int k=m[i].k;
		int t=0;
		while(k>0)
		{
			if(k>s[t])
			{
				k-=s[t];
				t++;
			}
			else if(k<=s[t])
			{
				for(int j=t;j>0;j--)
				{
					s[j]+=s[j-1];
					s[j-1]=0;
				}
				s[t]-=k;
				s[t+1]+=k;
				k=0;
				if(t+1>ed)ed=t+1;
			}
		}
		/*for(int i=0;i<=ed;i++)printf("%d ",s[i]);
		printf("\n\n");*/
	}
	
	long long ans=0;
	for(long long i=0;i<=ed;i++)ans+=(i*(i-1))/2*(long long)(s[i]);
	
	printf("%lld\n",ans);

	//printf("time:%2f\n",(float)(clock()-start)/CLOCKS_PER_SEC);
	

	return 0;
}

Compilation message

sails.cpp: In function 'int main()':
sails.cpp:16:10: warning: variable 'start' set but not used [-Wunused-but-set-variable]
  clock_t start;
          ^~~~~
sails.cpp:18:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
  ~~~~~^~~~~~~~~
sails.cpp:21:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d",&m[i].h,&m[i].k);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 376 KB Output is correct
2 Correct 2 ms 420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 504 KB Output is correct
2 Correct 571 ms 1216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 809 ms 1240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 615 ms 1600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1071 ms 2192 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1070 ms 2344 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1063 ms 2568 KB Time limit exceeded
2 Halted 0 ms 0 KB -